apache使用fastcgi配置python和php

来源:互联网 发布:数据库第六章课后答案 编辑:程序博客网 时间:2024/05/17 06:10
  1. centos安装php: yum install php php-devel
  2. centos自带apache2,查看apache版本rpm -qa | grep httpd,
    安装apache工具(apxs等)yum install httpd-devel
    httpd -l httpd -M 列出apache安装的扩展模块
  3. 如果要外网访问,需要关闭防火墙:
 /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.soLoadModule fastcgi_module modules/mod_fastcgi.soFastCGIExternalServer /home/qiu/workspace/p1/p1.fcgi -host 127.0.0.1:8080NAMEVirtualHost 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

  1. 使用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
0 0
原创粉丝点击