Flask app running with gunicorn and nginx is crash

2019-08-09 23:09发布

问题:

Can you please help? I am stuck.

My server is crashing at @return redirect(url_for(‘login’)) ,when I run it using gunicorn i.e. $gunicorn — bind 127.0.0.1:5000 -w 4 wsgi:app. Same issue arises when I run it using supervisor. The code is working fine when I run it normally i.e. python app.py

Appreciate any suggestions.

回答1:

Try using this config, might help you. Create a new file in /etc/nginx/sites-enabled/

server {
        listen 80 ;
        server_name abc.com;
        large_client_header_buffers 8 32k;
  if ($http_user_agent ~* Googlebot) {  
    return 403; 
  }
        access_log /var/log/nginx/access.log;
        location / {
                add_header 'Access-Control-Allow-Origin' "$http_origin";
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT';
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass https://127.0.0.1:5000;
                proxy_read_timeout 90;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_buffers 8 32k;
                proxy_buffer_size 64k;
        }
}

use

nginx -t reload

check the config