ubuntu14.10环境,apache2配置python的cgi

1,安装apache2,命令如下:

sudo apt-get install apache2

2,进入/var/www/目录,创建test.com目录,并修改拥有者权限,再在test.com目录下创建cgi-bin目录,命令分别如下:

sudo mkdir example.com
sudo chown -R $USER example.com
mkdir example.com/cgi-bin

3,创建hello.py文件,编辑内容如下(内容参考链接:http://www.yiibai.com/python/python_cgi_programming.html):

vim hello.py
chmod 755 hello.py
#!/usr/bin/python print "Content-type:text/html\r\n\r\n" print '<html>' print '<head>' print '<title>Hello Word - First CGI Program</title>' print '</head>' print '<body>' print '<h2>Hello Word! This is my first CGI program</h2>' print '</body>' print '</html>'

4,进入/etc/apache2/sites-available目录下,复制000-default.conf文件到example.com.conf文件,并修改并添加cgi配置:

修改:
DocumentRoot /var/www/example.com
添加: ScriptAlias
/cgi-bin/ /var/www/example.com/cgi-bin/ <Directory "/var/www/example.com/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all AddHandler cgi-script .py AddHandler default-handler .html .htm </Directory>

5,禁用默认cgi配置,在目录/etc/apache2/conf-available/serve-cgi-bin.conf;禁用默认配置000-default.conf;启用example.com.conf配置;并重启apache2

sudo a2disconf serve-cgi-bin.conf
sudo a2dissite 000-default.conf sudo a2ensite example.com.conf sudo service apache2 restart

6,配置sudo编辑/etc/hosts文件:

127.0.0.1    www.example.com

7,访问浏览器www.example.com/cgi-bin/hello.py,应该能看到结果



转载于:https://www.cnblogs.com/doublehappyi/p/4753225.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值