码迷,mamicode.com
首页 > 其他好文 > 详细

gunicorn模块(django与nginx整合)

时间:2017-03-31 22:01:00      阅读:409      评论:0      收藏:0      [点我收藏+]

标签:gunicorn模块(django与nginx整合)

gunicorn模块


1、安装gunicorn

[root@133 ~]# yum search nginx
[root@133 ~]# yum install -y nginx.x86_64
[root@133 ~]# /etc/init.d/nginx restart
nginx: [warn] conflicting server name "112.65.140.132" on 0.0.0.0:80, ignored
停止 nginx:                                               [失败]
正在启动 nginx:nginx: [warn] conflicting server name "112.65.140.132" on 0.0.0.0:80, ignored
                                                          [确定]

2、测试nginx

技术分享


3、安装gunicorn

[root@133 ~]# pip install gunicorn


4、修改nginx的配置文件

[root@133 simplecmdb]# vim /etc/nginx/conf.d/virtual.conf
# A virtual host using mix of IP-, name-, and port-based configuration
server {
   listen       112.65.140.133:8000;
   server_name  www.daixuan.com;

   location /static/admin {
       root   /opt/amos/lib/python2.7/lib/python2.7/site-packages/django/contrib/admin;
       index  index.html index.htm;
   }

   location / {
       proxy_pass http://localhost:8000;
   }
}

[root@133 simplecmdb]# service nginx restart
nginx: [warn] conflicting server name "112.65.140.132" on 0.0.0.0:80, ignored
停止 nginx:                                               [确定]
正在启动 nginx:nginx: [warn] conflicting server name "112.65.140.132" on 0.0.0.0:80, ignored
                                                          [确定]

访问:http://112.65.140.133:8000/   返回502 


5、启用gunicorn

[root@133 simplecmdb]# cd /opt/python/django/simplecmdb-gunicorn/
[root@133 simplecmdb-gunicorn]# ls
112.65.140.132  exit  hostinfo  manage.py  nohup.out  simplecmdb  sysinformation-pickle.py

[root@133 simplecmdb-gunicorn]# gunicorn simplecmdb.wsgi:application -D
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site
根据提示:安装site模块
[root@133 simplecmdb-gunicorn]# pip install site
Collecting site
/opt/amos/python2.7/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/opt/amos/python2.7/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading site-0.0.1.tar.gz
Installing collected packages: site
  Running setup.py install for site ... done
Successfully installed site-0.0.1
[root@133 simplecmdb-gunicorn]# vim /etc/profile
export PYTHONHOME=/opt/amos/python2.7
[root@133 simplecmdb-gunicorn]# source /etc/profile
[root@133 simplecmdb-gunicorn]# echo $PYTHONHOME
/opt/amos/python2.7
[root@133 simplecmdb-gunicorn]# pwd
/opt/python/django/simplecmdb-gunicorn
[root@133 simplecmdb-gunicorn]# gunicorn simplecmdb.wsgi:application -D
[root@133 simplecmdb-gunicorn]# netstat -anput | grep :80
tcp        0      0 127.0.0.1:8000              0.0.0.0:*                   LISTEN      8106/python2.7
tcp        0      0 112.65.140.133:8000         0.0.0.0:*                   LISTEN      7817/nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      7817/nginx
tcp        0    531 112.65.140.133:63251        182.50.136.239:80           FIN_WAIT1   -
tcp        0      0 :::80                       :::*                        LISTEN      7817/nginx
可以看到-D 指定的127.0.0.1上开启的端口


5、访问测试

技术分享 

技术分享


技术分享技术分享


这里css等文件被403了,所以肯定是用户权限问题。user从nginx修改为root,然后重启nginx即可。

[root@133 simplecmdb-gunicorn]# vim /etc/nginx/nginx.conf
user root;



本文出自 “梅花香自苦寒来!” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1912250

gunicorn模块(django与nginx整合)

标签:gunicorn模块(django与nginx整合)

原文地址:http://daixuan.blog.51cto.com/5426657/1912250

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!