安装并启动 httpd
sudo yum install httpd
sudo systemctl enable httpd
sudo systemctl start httpd
主配置文件是/etc/httpd/conf/httpd.conf。
配置存储在的/etc/httpd/conf.d/目录。
# wsgi
#LoadModule wsgi_module modules/mod_wsgi.so
LoadModule wsgi_module "/usr/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/usr"
WSGIPythonPath /var/git-project/mypythonwork/django_project/mysite
<VirtualHost *:80>
WSGIScriptAlias /test /var/git-project/mypythonwork/django_project/mysite/mysite/wsgi.py
Alias /static/ /var/git-project/mypythonwork/django_project/mysite/static/
ServerName xxx.xxx.xxx.xxx
<Directory /var/git-project/mypythonwork/django_project/mysite/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /var/git-project/mypythonwork/django_project/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog /etc/httpd/logs/myproject.error.log
LogLevel warn
</VirtualHost>
配置文件需要根据下文进行对应修改
安装mod_wsgi
安装httpd python36 开发包,
yum install -y httpd-devel
yum install python36-devel
然后用 pip 安装 mod-wsgi
pip3 install mod-wsgi
然后 调用 mod_wsgi-express module-config 就可以得到 前面需要的配置
LoadModule wsgi_module "/usr/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/usr"
跟随官方教程 创建 django 项目
然后 在 settings.py项目设置中
配置 ALLOWED_HOSTS 为服务器IP
最后一行添加STATIC_ROOT = '/var/django-project/mysite/static/'
收集静态文件
运行 python36 manage.py collectstatic
重启httpd
apachectl configtest
apachectl restart
配置完成