centos7+flask+Gunicorn+nginx

1,安装Gunicorn

pip install Gunicorn

gunicorn --workers=2 app:app -b 0.0.0.0:8080(app是py文件名,8080为端口号)

2,安装nginx

# yum install nginx 
sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
sudo vi /etc/nginx/nginx.conf

  

修改其中的server部分

user nginx;
 worker_processes auto;
 error_log /var/log/nginx/error.log;
 pid /run/nginx.pid;
 include /usr/share/nginx/modules/*.conf;
 events {
     worker_connections 1024;
 }
 http {
     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
     access_log  /var/log/nginx/access.log  main;
     sendfile            on;
     tcp_nopush          on;
     tcp_nodelay         on;
     keepalive_timeout   65;
     types_hash_max_size 2048;
     include             /etc/nginx/mime.types;
     default_type        application/octet-stream;
     server {
         listen       80 default_server;
         listen       [::]:80 default_server;
         server_name  _;
         root         /usr/share/nginx/html;
 
         # Load configuration files for the default server block.
         include /etc/nginx/default.d/*.conf;
 
         location / {
         }
 
         error_page 404 /404.html;
             location = /40x.html {
         }
                                                                                                                                                                                                       
         error_page 500 502 503 504 /50x.html;
             location = /50x.html { 
         }   
     }   
     server {
         listen 8080;
         server_name www.wengdell.com; # 这是HOST机器的外部域名,用地址也行
     
         location / {
             proxy_pass http://127.0.0.1:8000; # 这里是指向 gunicorn host 的服务地址
             proxy_set_header Host $host;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         }   
     
     }

  

  

开启nginx服务并开机自启

# systemctl start nginx
# systemctl enable nginx
 
 
原文地址:https://www.cnblogs.com/lza945/p/14237292.html