为什么 NGINX 给出 504 网关超时错误?
Why is NGINX giving 504 gateway timeout error?
我的 NGINX
配置文件是-
server {
listen 80;
server_name site.com ;
location / {
include proxy_params;
proxy_pass http://0.0.0.0:8000;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
我是 运行 Port 8000
Gunicorn
上的 Flask 应用程序。当我尝试访问我的网站时,我得到 504 Gateway Time-out
nginx/1.14.0 (Ubuntu)
.
在 error.log
中,它说-
upstream timed out (110: Connection timed out) while connecting to upstream, client:myip server: site.com, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:8000/", host: "mysite.com"
您的配置有一些错误。
- 您不能让一台服务器监听多个端口。
- 你不应该写 0.0.0.0:8000,而是尝试写 127.0.0.1:8000
另外我不明白为什么要包含代理参数,只需删除该行即可。
这是您可以执行的操作的示例。
server {
server_name site.com www.site.com;
location / {
proxy_pass http://127.0.0.1:8000/;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = www.site.com) {
return 301 https://$host$request_uri;
}
if ($host = site.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name site.com www.site.com;
return 404;
}
祝你好运:-)
建议保持如下值,这样可以解决超时问题。
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
我的 NGINX
配置文件是-
server {
listen 80;
server_name site.com ;
location / {
include proxy_params;
proxy_pass http://0.0.0.0:8000;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
我是 运行 Port 8000
Gunicorn
上的 Flask 应用程序。当我尝试访问我的网站时,我得到 504 Gateway Time-out
nginx/1.14.0 (Ubuntu)
.
在 error.log
中,它说-
upstream timed out (110: Connection timed out) while connecting to upstream, client:myip server: site.com, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:8000/", host: "mysite.com"
您的配置有一些错误。
- 您不能让一台服务器监听多个端口。
- 你不应该写 0.0.0.0:8000,而是尝试写 127.0.0.1:8000
另外我不明白为什么要包含代理参数,只需删除该行即可。
这是您可以执行的操作的示例。
server {
server_name site.com www.site.com;
location / {
proxy_pass http://127.0.0.1:8000/;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = www.site.com) {
return 301 https://$host$request_uri;
}
if ($host = site.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name site.com www.site.com;
return 404;
}
祝你好运:-)
建议保持如下值,这样可以解决超时问题。
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;