centos7 使用 apache2.4 + mod_wsgi 部署django项目
程序员文章站
2022-06-11 12:03:30
...
使用 apache2.4 + mod_wsgi 部署django项目
一、软件安装
1.安装httpd(apache2.4)
yum install httpd
yum install httpd-devel
# 运行测试,需保证端口不被占用
systemctl start httpd
2.编译安装mod_wsgi (version 4.6.4)
参考连接:https://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html
2.1 下载mod_wsgi源码并解压
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.4.tar.gz
tar xvfz 4.6.4.tar.gz
2.2 配置源代码并安装
cd mod_wsgi-4.6.4/
./configure --with-python=/usr/bin/python3.6
make
make install
3.将模块加载到Apache
vim /etc/httpd/conf/httpd.conf
#追加一行
LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so
4.重启Apache服务
systemctl restart httpd
# 或者 apachectl restart
5.清理编译后的源代码(Optional)
make clean
二、编写Apache配置文件
参考链接:https://docs.djangoproject.com/zh-hans/2.1/howto/deployment/wsgi/modwsgi/#daemon-mode
cd /etc/httpd/conf.d/
vim mysite.conf
# 如下配置
WSGIScriptAlias / /var/www/mysite.com/mysite/wsgi.py
#WSGIPythonHome /var/www/venv
#WSGIPythonPath /var/www/mysite
WSGIDaemonProcess mysite.com processes=2 threads=15 python-home=/var/www/venv python-path=/var/www/mysite.com
WSGIProcessGroup mysite.com
<Directory /var/www/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /robots.txt /var/www/mysite.com/static/robots.txt
Alias /favicon.ico /var/www/mysite.com/static/favicon.ico
Alias /media/ /var/www/mysite.com/media/
Alias /static/ /var/www/mysite.com/static/
<Directory /var/www/mysite.com/static>
Require all granted
</Directory>
<Directory /var/www/mysite.com/media>
Require all granted
</Directory>
重启服务即可
apachectl restart
注:如有必要,需要注释掉welcome.conf的内容。
上一篇: asp.net返回JSON格式数据总结