Nginx+uWSGI部署

uwsgi中文文档
先确保项目在虚拟环境下可以正常运行。
可以尝试一下python manage.py runserver 0.0.0.0:80
先安装uwsgi

pip3 install uwsgi

安装完uwsgi之后,一定要根据文档的流程中的这一步
因为执行这一步的时候,就可能会出错,错误会在终端面板出现。我遇到就是引用Python的版本出错了。
因为不尝试一下下面的一步,后面就可能就会出错。
uwsgi --http :9090 --wsgi-file foobar.py
成功之后,要kill掉进程,不然后面会提示端口被占用。

安装nginx

apt-get install nginx

nginx目录

/etc/nginx

创建自己的.conf

cd /etc/nginx/sites-available
vim projectname.conf

	projectname.conf

server {
listen 80;
server_name projectname;
charset utf-8;

client_max_body_size 75M;

location /favicon.ico {
	alias /home/projectname/favicon.ico;
}
location /static {
	alias /home/profectname/static;
}

location /media {
	alias /home/projectname/media;
}

location / {
	uwsgi_pass 127.0.0.1:8000; #根据自己项目来定
	include /etc/nginx/uwsgi_params;
	}
}

这里要通过软链接把sites-available 链接到sites-enabled

ln -s /etc/nginx/sites-available/projectname.conf /etc/nginx/sites-enabled/projectname.conf

创建目录 project_uwsgi
目录位置根据自己设置,方便即可

cd project_uwsgi
vim projectname.ini

		projectname.ini
[uwsgi]
chdir = /home/projectname   #主目录
home = /home/projectname_env    #虚拟环境
module = projectname.wsgi:application

master = True
processes = 4
max-requests = 5000
socket =127.0.0.1:8000
uid = 1000
gid = 2000

pidfile =  /project_uwsgi/master.pid							# 最好写全路径
daemonize = /project_uwsgi/projectname.log			#最好写全路径
vacuum = True

uwsgi命令

ps -aux | grep uwsgi
出现多个一般来说是成功的,一个就是不成功
下面命令都需要完整路径
uwsgi --ini projectname.ini #启动
uwsgi --reload /master.pid #重启
uwsgi --stop  /master.pid #停止

nginx命令

nginx -t
service nginx restart
service nginx stop
service nginx status
service nginx status

还有一个,要给media/ 777权限

chmod 777 media/

nginx的日记文件在下面的路径中,可以在nginx的安装目录/etc/nginx/nginx.conf中查看.
在这里插入图片描述

uwsgi的日记在我们.ini定义的文件下如上面的project.log

猜你喜欢

转载自blog.csdn.net/qq_40965177/article/details/83962001