apache使用fastcgi配置python和php

  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.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 [email protected]
    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 [email protected]                         
    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配置:
192.168.43.128:80>  # python gunicorn
    ServerAdmin xiaoqiu206@163.com
    ServerName gunicorn.test.com
    ProxyRequests Off
    
        Order deny,allow
        Allow from all
    
    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/ 
    "/static/">
        Order allow,deny
        Options Indexes
        Allow from all
        IndexOptions FancyIndexing
    

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

你可能感兴趣的:(linux)