大佬教程收集整理的这篇文章主要介绍了nginx 部署flask应用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
需要掌握的命令
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配置文件是否正确
以下配置文件中的路径都采用的绝对路径
user root;
events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # set to 'on' if Nginx worker_processes > 1
# 'use epoll;' to enable for Linux 2.6+
# 'use kqueue;' to enable for FreeBSD, OSX
}
http {
include /etc/Nginx/mime.types;
# fallback in case we can't determine a type
default_type application/octet-stream;
access_log /home/f7689984/NginxLog/access.log combined;
sendfile on;
upstream app_server {
# fail_timeout=0 means we always retry an upstream even if it Failed
# to return a good HTTP response
# for UNIX domain socket setups
server unix:/tmp/gunicorn.sock fail_timeout=0;
# for a TCP configuration
# server 192.168.0.7:8000 fail_timeout=0;
}
server {
# use 'listen 80 deferred;' for Linux
# use 'listen 80 accept_filter=httpready;' for FreeBSD
# 监听80端口访问并转发到http://10.134.82.195:8000
listen 80;
client_max_body_size 4G;
# set the correct host(s) for your site
server_name 10.134.82.195;
keepalive_timeout 5;
# path for static files
# root /app/static;
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;
}
# error_page 500 502 503 504 /500.html;
# location = /500.html {
# root /path/to/app/current/public;
# }
}
}
1.将Nginx安装好
2.启动flask应用
# 使用nohup后台gunicorn启动flask应用
nohup gunicorn -c gunicorn.conf.py run:app >/dev/null 2>&1 &
3.编辑好Nginx配置文件并启动
sudo Nginx -c Nginx.conf
开启Nginx后静态资源访问出现403报错
user root;
再次启动解决问题。
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
以上是大佬教程为你收集整理的nginx 部署flask应用全部内容,希望文章能够帮你解决nginx 部署flask应用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。