apache使用fastcgi配置python和php
Posted 黑猫-警长
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache使用fastcgi配置python和php相关的知识,希望对你有一定的参考价值。
- centos安装php: yum install php php-devel
- centos自带apache2,查看apache版本
rpm -qa | grep httpd
,
安装apache工具(apxs等)yum install httpd-devel
httpd -l httpd -M 列出apache安装的扩展模块 - 如果要外网访问,需要关闭防火墙:
/etc/init.d/iptables stop
# 或者是
centos7:
systemctl stop firewalld.service # 停止
systemctl disable firewalld.service # 禁用
之前的版本:
service iptables stop # 停止
chkconfig iptables off # 禁用
关闭selinux. 查看selinux状态使用/usr/sbin/sestatus -v
如果SELinuxstatus参数为enable则为开启状态
暂时关闭(不用重启)可以用 setenforce 0
4. python安装flup,apache安装mod_fastcgi
5. apache配置:
ServerName localhost:80 # 第275行左右,要修改
# 最后面加上这些
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule fastcgi_module modules/mod_fastcgi.so
FastCGIExternalServer /home/qiu/workspace/p1/p1.fcgi -host 127.0.0.1:8080
NAMEVirtualHost 192.168.43.128:80
<VirtualHost 192.168.43.128:80>
DocumentRoot /home/qiu/workspace/p1
ServerAdmin xiaoqiu206@163.com
ServerName python.test.com
Alias /static /home/qiu/workspace/p1/static
RewriteEngine On
ErrorLog "/home/qiu/workspace/p1/log"
RewriteRule ^/(static.*)$ /$1 [QSA,L,PT]
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^/(.*)$ /p1.fcgi/$1 [L]
</VirtualHost>
<VirtualHost 192.168.43.128:80> ##### php项目的配置
ServerAdmin example1@126.com
DocumentRoot "/home/qiu/Documents/php"
ServerName php.test.com
ErrorLog "logs/ce.err"
CustomLog "logs/ce.access" common
<Directory "/your/path/php">
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
注意点:文件必须可读
python启动方式: python manage.py runfcgi protocol=fcgi method=threaded host=127.0.0.1 port=8080 deamonize=false
- 使用apache和gunicorn.
使用apache的反向代理
apache配置:
<VirtualHost 192.168.43.128:80> # python gunicorn
ServerAdmin xiaoqiu206@163.com
ServerName gunicorn.test.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /static/ !
ProxyPass / http://127.0.0.1:8888/
ProxyPassReverse / http://127.0.0.1:8888/
# 有的教程加上了这2行
# ProxyPreserveHost On
# ProxyErrorOverride Off
Alias /static/ /usr/local/python/lib/python2.7/site-packages/django/contrib/admin/static/
<Directory "/static/">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
gunicorn启动方式:
进入到工程目录下,gunicorn p1.wsgi:application -b 127.0.0.1:8888
或者 gunicorn -k egg:meinheld#gunicorn_worker p1.wsgi:application -b 127.0.0.1:8888
或者 gunicorn -k gevent p1.wsgi:application -b 127.0.0.1:8888
全局的NAMEVirtualHost 192.168.43.128:80可以改写为
NAMEVirtualHost *:80
然后VirtualHost里的IP:PORT也都可以改成
VirtualHost *:80
以上是关于apache使用fastcgi配置python和php的主要内容,如果未能解决你的问题,请参考以下文章
apache中配置php支持模块模式cgi模式和fastcgi模式
sh 翻译:“OS X 10.10 Yosemite本地开发环境,Apache,PHP和MySQL与Homebrew”:5。配置Apache,PHP,PHP-FPM和mod_fastcgi,配置使用`