500 内部服务器错误 Nginx 运行反应应用程序



按照这个答案,我把我的nginx服务器设置成这样:

server {
server_name portal.productive.city www.portal.productive.city;
root /www/Productive-Website/my-app/build;
index index.html index.htm;
rewrite ^/(.*)/$ $1 permanent;
location / {
try_files $uri?$args $uri/ $uri.html?$args /index.html?$args;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/portal.productive.city/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/portal.productive.city/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
}

我的另一个服务器(在同一文件中((由lets-encrypt创建(是:

server {
if ($host = www.portal.productive.city) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = portal.productive.city) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name portal.productive.city www.portal.productive.city;
return 404; # managed by Certbot
}

当我尝试转到:www.portal.productive.city 或 www.portal.productive.city/signin 时,我收到500 内部服务器错误

我的错误日志文件如下所示:

2018/08/31 14:43:08 [错误] 29581#29581:*25 重写或内部 内部重定向到"/index.html"时的重定向循环, 客户端:74.105.149.67,服务器:portal.productive.city,请求:"GET/HTTP/1.1", 主机: "www.portal.productive.city"

2018/08/31 14:43:08 [错误] 29581#29581:*26 重写或内部重定向循环,而 内部重定向到"/index.html",客户端:74.105.149.67, server: portal.productive.city, request: "GET/favicon.ico HTTP/1.1", 主持人:"www.portal.productive.city",推荐人: "https://www.portal.productive.city/">

网站图标.ico存在于path/to/repo/build

编辑:我清除了缓存并重组了服务器,如下所示:

server {
server_name portal.productive.city www.portal.productive.city;
root /www/Productive-Website/my-app/build;
index index.html index.htm;
location / {
try_files $uri?$args $uri/ $uri.html?$args /index.html?$args;
}
listen 80;
if ($scheme != "https") {
return 301 https://$host$request_uri?$args;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/portal.productive.city/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/portal.productive.city/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
}

错误文件现在是:

2018/08/31 15:17:54 [错误] 29789#29789:*17 重写或内部 内部重定向到"/index.html"时的重定向循环, 客户端:74.105.149.67,服务器:portal.productive.city,请求:"GET/?HTTP/1.1", 主机: "www.portal.productive.city"

2018/08/31 15:17:54 [错误] 29789#29789:*18 重写或内部重定向循环,而 内部重定向到"/index.html",客户端:74.105.149.67, server: portal.productive.city, request: "GET/favicon.ico HTTP/1.1", 主持人:"www.portal.productive.city",推荐人: "https://www.portal.productive.city/?">

您不应该有 2 个具有相同server_name的服务器文件,这使您的配置更难找到。而且,如果您偶然将它们都配置为侦听相同的端口,则会混淆 NGINX 在哪个端口上渲染。首先,将它们移动到同一个中,并根据$scheme而不是$host重定向。但这不是真正的问题。您有一个循环的重定向,因为它匹配以"/"结尾的每个请求

server {
server_name portal.productive.city www.portal.productive.city;
root /www/Productive-Website/my-app/build;
index index.html index.htm;
# rewrite ^/(.*)/$ $1 permanent; Your REAL problem is here. You've got an redirect that is looping because it matches every request ending with '/'
location / {
try_files $uri?$args $uri/ $uri.html?$args /index.html?$args;
}
listen 80;
if ($scheme != "https") {
return 301 https://$host$request_uri?$args
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/portal.productive.city/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/portal.productive.city/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
}

https 重定向的意思是:"如果$scheme不是'https',请重定向到https://$host$request_uri?$args"。翻译为:"https://地址在同一主机上,在同一路径上,并且具有访问中使用的相同URL参数"。

相关内容

最新更新