使用uwsgi+nginx部署项目

Uwsgi:部署web应用程序

Nginx:反向代理,静态服务器 

1.修改uwsgi配置文件》nginx反向代理[nginx接收请求-》传递-》[uwsgi] http=.. --socket=..

为了保证项目的访问安全,ip地址变为本机地址

在manage.py同目录下新建uwsgi.ini文件并配置

[uwsgi]

Socket=127.0.0.1:8000

Chdir=..

Wsgi-file=..

Master=..

Process=..

#static-map=..注释掉,静态文件有nginx代理 

 uwsgi.ini 

[uwsgi]
#http=192.168.132.128:8000
socket=127.0.0.1:8000
chmod-socket=666
chdir=/home/op/桌面/django-pfeiliu/pfeiliu
wsgi-file=pfeiliu/wsgi.py
processes=4 
threads=2 
master=true
pidfile=uwsgi.pid
daemonize=uwsgi.log
#static-map=/static=static-file

 2.确认是否安装nginx

命令行安装:apt-get install nginx

源代码安装:wget http://nginx.org/download/nginx-1.6.2.tar.gz

-》解压 tar xzvf ...tar.gz

-make & make install

修改nginx配置文件vim  /etc/nginx/nginx.conf

添加虚拟服务器配置[server]

添加反向代理路由配置[location - uwsgi_pass]

添加静态文件服务器路由配置[location - alias]

重启nginx

nginx对静态文件的处理优于uwsgi

Uwsgi对动态文件的处理优于nginx

 

http中添加server

server {

listen 80;

server_name 192.168.37.128;

location / {

include uwsgi_params;

Uwsgi_pass 127.0.0.1:8000;

}

location /static {

alias 静态文件地址;

}

}

 /etc/nginx/nginx.conf

静态文件收集请参考方式1  https://www.cnblogs.com/pfeiliu/p/11922843.html

............................................
server { listen
80; server_name 192.168.132.128; #charset koi8-r; #access_log logs/host.access.log main; location / { include /usr/local/nginx/conf/uwsgi_params; uwsgi_pass 127.0.0.1:8000; } location /static { alias /home/tarena/桌面/django-pfeiliu/pfeiliu/static-file; } }
............................................
 

 

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

解决方法:sudo killall -9 nginx 

 

开启nginx:server nginx start

重启nginx:server nginx restart

关闭nginx:server nginx stop

测试nginx:nginx -t   # 如果是nginx的问题,可以通过测试发现原因。

 

启动项目:

启动nginx/usr/local/webserver/nginx/sbin/nginx

启动uwsgiuwsgi --ini uwsgi.ini

浏览器输入ip,即可访问

关闭项目:

杀死nginx进程:sudo killall -9 nginx 

杀死nginx进程:sudo killall -9 uwsgi  

 

 

 

代码布局如下:

 

 

 

posted @ 2019-11-24 16:24  腹肌猿  阅读(363)  评论(0编辑  收藏  举报