Python+Apache环境搭建

Python+Apache环境搭建

Python+apache搭建时需要apache拓展mod_wsgi模块,apache启动时自动加载mod_wsgi模块,通过mod_wsgi与python通信,实现python部署在apache上。

安装

  • 1.下载源码包mod_wsgi
  • 2.解压缩mod_wsgi包 tar zxvf mod_wsgi-4.6.8.tar.gz -C .
  • 3.进入mod_wsgi目录下 cd mod_wsgi-4.6.8
  • 4.编译mod_wsgi,指定apache和python ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/local/python3/bin/python3.7
  • 5.安装 make && make install

配置

  • 1.在apache配置文件中载入mod_wsgi模块
    vim /usr/local/apache2/conf/httpd.conf LoadModule wsgi_module modules/mod_wsgi.so
  • 2.在apache配置中加入python指定环境
    vim /usr/local/apache2/conf/extra/http-ssl.conf
    加入python所在位置
    WSGIPythonHome /usr/local/python3
  • 3.增加一个虚拟主机的配置
    vim /usr/local/apache2/conf/extra/http-ssl.conf
<VirtualHost *:9052>
WSGIScriptAlias / 路径/htdocs/myapp/runapp.wsgi
<Directory /路径/htdocs/myapp>
AllowOverride AuthConfig FileInfo
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
  • 4.重启apache