首页 > 代码库 > gunicorn模块(django与nginx整合)
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整合)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。