1. 程式人生 > >django專題—整合apache、整合nginx

django專題—整合apache、整合nginx

isoc httpd ant service python2.7 htm ssg run djiango

八、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

<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結合nginx—gunicron模塊

1)安裝模塊,需要epel擴展源

yum install -y nginx

pip install gunicron


2)修改nginx的配置文件

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;
}
}


技術分享圖片

技術分享圖片

3)啟動配置文件和nginx

gunicorn simplecmdb.wsgi:application -D

systemctl start nginx.service


技術分享圖片技術分享圖片


4)啟動nginx,查看

技術分享圖片技術分享圖片


django專題—整合apache、整合nginx