Nginx 不断重定向
Nginx constantly redirecting
我第一次部署这样的应用程序,运行 一个与 BE 分开的 FE 容器。目前,此设置最终会无休止地重定向。知道为什么吗?
该域的服务器 nginx
server {
listen 80;
server_name domain;
return 301 https://domain$request_uri;
client_max_body_size 0;
}
server {
server_name domain;
error_log /var/log/nginx/dom_error.log;
access_log /var/log/nginx/dom_access.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:1904;
add_header X-Host $host;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain/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
}
该应用程序的 nginx
server {
listen 80;
server_name domain;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://fe:3000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /api {
proxy_pass http://be:8000/api;
}
location /mongo {
proxy_pass http://mongodb:8081;
}
}
知道这里出了什么问题吗?
对我来说有点不明显的配置,你的 ide 可能需要更具体的解释,但就只有一个重定向 return 301 https://domain$request_uri;
我认为你可以尝试不同的方式:
if ($scheme = "http") {
return 301 https://$server_name$request_uri;
}
我也没有得到 client_max_body_size 0;
配置条目,你明白为什么它在那里吗?
原来这个问题是 nginx conf 没有正确重置并且没有传播更改。此配置工作正常。修改配置后记得重新加载!
我第一次部署这样的应用程序,运行 一个与 BE 分开的 FE 容器。目前,此设置最终会无休止地重定向。知道为什么吗?
该域的服务器 nginx
server {
listen 80;
server_name domain;
return 301 https://domain$request_uri;
client_max_body_size 0;
}
server {
server_name domain;
error_log /var/log/nginx/dom_error.log;
access_log /var/log/nginx/dom_access.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:1904;
add_header X-Host $host;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain/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
}
该应用程序的 nginx
server {
listen 80;
server_name domain;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://fe:3000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /api {
proxy_pass http://be:8000/api;
}
location /mongo {
proxy_pass http://mongodb:8081;
}
}
知道这里出了什么问题吗?
对我来说有点不明显的配置,你的 ide 可能需要更具体的解释,但就只有一个重定向 return 301 https://domain$request_uri;
我认为你可以尝试不同的方式:
if ($scheme = "http") {
return 301 https://$server_name$request_uri;
}
我也没有得到 client_max_body_size 0;
配置条目,你明白为什么它在那里吗?
原来这个问题是 nginx conf 没有正确重置并且没有传播更改。此配置工作正常。修改配置后记得重新加载!