nginx 部署项目不要想的太过复杂,直接上手操作,遇到问题再逐个击破
编程语言:python
项目后端:flask
前端:vue 2.x
准备工作
需要掌握的命令
sudo nginx -c nginx.conf :指定配置文件启动nginx
nginx -s stop :快速停止nginx
nginx -s quit :完整有序的停止nginx
start nginx : 启动nginx
nginx -s reload :修改配置后重新加载生效
nginx -s reopen :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确
配置好nginx.conf
以下配置文件中的路径都采用的绝对路径
user root;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /home/f7689984/nginxLog/access.log combined;
sendfile on;
upstream app_server {
server unix:/tmp/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
client_max_body_size 4G;
server_name 10.134.82.195;
keepalive_timeout 5;
location / {
root /home/f7689984/bm-hub/app/dist;
proxy_pass http://10.134.82.195:8000;
index index.html;
}
location /static/ {
root /home/f7689984/bm-hub/app/;
autoindex off;
}
}
}
具体步骤
1.将nginx安装好
2.启动flask应用
nohup gunicorn -c gunicorn.conf.py run:app >/dev/null 2>&1 &
3.编辑好nginx配置文件并启动
sudo nginx -c nginx.conf
关于遇到的问题
1.开启nginx后静态资源访问出现403报错
查阅资料发现可能是文件权限不足的问题,关闭nginx
修改nginx.conf的用户权限
在第一行加入
user root;
再次启动解决问题。
2.502 bad gateway
很简单,很可能就是因为监听的地址没有写对或者被监听的项目没有启动
部署参考
https://qizhanming.com/blog/2018/08/06/how-to-install-nginx-on-centos-7
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
https://wizardforcel.gitbooks.io/the-way-to-flask/content/chapter013.html
https://stackoverflow.com/questions/42329261/running-nginx-as-non-root-user
Original: https://blog.csdn.net/weixin_41831623/article/details/113939798
Author: 阿珂来了
Title: nginx 部署flask应用
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/747790/
转载文章受原作者版权保护。转载请注明原作者出处!