电竞比分网-中国电竞赛事及体育赛事平台

分享

在ubuntu下配置apache運(yùn)行python腳本

 ProgramBird 2015-01-23
常用的簡單命令
sudo apt-get remove --purge apache apache2 (徹底刪除)

sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop

sudo makedir /home/htdocs
sudo chmod 777 /home/htdocs 生成網(wǎng)站目錄,并修改權(quán)限

ubuntu下apache的配置文件一般放在/etc/apache2/這個(gè)目錄下,與windows不同的是在這里配置文件被分成幾部分,主要有apache2.conf, httpd.conf, sites-available/default幾個(gè)
----------------------------------------------------------
主配置文件 apache2.conf,基本不用修改,
在該文件中我們可以看到有這么一行內(nèi)容: Include /etc/apache2/sites-enabled/[^.#]*
這行的意思表明該文件包含了 /etc/apache2/sites-enabled/ 目錄中文件名不含 "." 或 "#" 這兩個(gè)字符的所有文件。而當(dāng)我們列出該目錄的文件時(shí),發(fā)現(xiàn)只有一個(gè) 000-default 的軟鏈接文件,實(shí)際連接的是 /etc/apache2/sites-available 目錄中的 default 文件,不難看出該文件的文件名中并不包含 "." 或 "#"。所以這個(gè)文件當(dāng)然是要被配置文件 apache2.conf 所包含的了。打開該文件,發(fā)現(xiàn)它其實(shí)是一個(gè)虛擬主機(jī)的配置文件,不過由于該文件中的虛擬主機(jī)為 *,所以它實(shí)際上是一個(gè)通用配置文件。

sites-available/default:
* NameVirtualHost *:表示我們要做的是一個(gè)基于名稱的虛擬主機(jī)
* <VirtualHost *> 和 </VirtualHost>:表示在其中的是一個(gè)虛擬主機(jī)的配置
* ServerName :設(shè)置虛擬主機(jī)的域名
* ServerAdmin [email=webmaster@gmail.com][color=#0000ff]webmaster@gmail.com[/color][/email]:設(shè)置該虛擬主機(jī)網(wǎng)管員的郵件
* DocumentRoot /var/www/:設(shè)置該虛擬主機(jī)的主目錄路徑
* ErrorLog /var/log/apache2/error.log:設(shè)置該虛擬主機(jī)的出錯(cuò)信息
* CustomLog /var/log/apache2/access.log combined:設(shè)置該虛擬主機(jī)的訪問信息

httpd.conf 用戶的配置
添加
DirectoryIndex index.html index.html.var index.htm
AddType text/html .htm .html .py
AddHandler cgi-script .cgi .py

測試配置成功與否

保存一個(gè)如下內(nèi)容的文件,比如命名為 helloworld.py 文件到定義的cgi文件夾中。

代碼:
#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello, World."

然后賦予可執(zhí)行權(quán)限

代碼:
sudo chmod a+x helloworld.py


最后重啟一下apache2

代碼:
sudo /etc/init.d/apache2 restart


在瀏覽器地址欄里輸入:http://localhost/cgi-bin/helloworld.py
,看到了Hello,World. 至此我們大功告成。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多