django专题—整合apache与nginx

八、Djiango结合apache—wsgi模块

1)安装模块

yum install -y mod_wsgi

yum install -y httpd


说明:apache 自动加载配置文件模块

cat /etc/httpd/conf.modules.d/10-wsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so


2)创建一个新的配置文件

cat /etc/httpd/conf.d/django.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<VirtualHost *:80>
WSGIDaemonProcess simplecmdb python-path=/opt/simplecmdb:/usr/lib64/python2.7/site-packages
WSGIProcessGroup simplecmdb
WSGIScriptAlias / /opt/simplecmdb/simplecmdb/wsgi.py
Alias /static /usr/lib64/python2.7/site-packages/django/contrib/admin/static
</VirtualHost>
 
<Directory "/opt/simplecmdb/simplecmdb">
Require all granted
</Directory>
 
<Directory "/usr/lib64/python2.7/site-packages/django/contrib/admin/static">
Require all granted
</Directory>
 
WSGISocketPrefix /var/run/wsgi

说明:/opt 为项目路径,可以先拷贝出来,不能是root目录下;以及jdango包所在的路径

cp -rp simplecmdb/ /opt/

chown -R apache:apache /opt/simplecmdb


3)启动apache


4)访问

django专题—整合apache与nginx



九、django结合nginx—gunicron模块

1)安装模块,需要epel扩展源

yum install -y nginx

pip install gunicron


2)修改nginx的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat /etc/nginx/conf.d/virtual.conf
server {
listen 192.168.2.230:9000;
server_name localhost;
 
location /static/admin {
root /usr/lib64/python2.7/site-packages/django/contrib/admin/;
index index.html index.htm;
}
 
location / {
proxy_pass http://localhost:8000;
}
}


django专题—整合apache与nginx

3)启动配置文件和nginx

gunicorn simplecmdb.wsgi:application -D

systemctl start nginx.service


django专题—整合apache与nginx


4)启动nginx,查看

django专题—整合apache与nginx










本文转自 huangzp168 51CTO博客,原文链接:http://blog.51cto.com/huangzp/2057528,如需转载请自行联系原作者