我正在尝试使用 nginx 在数字海洋上部署 React Web App。
我的根指向我的 git 存储库中的 build 文件夹。这样我就可以在我进行更改时通过 git pull 更新我的应用程序。
起初,一切正常,但后来我做了一个 git pull ,现在我收到重定向错误或 500 个错误。我不确定发生了什么。
如果我在浏览器中打开网站到主页,它只会显示一个空白的白屏。如果我尝试访问子域,则会出现 500 内部错误。
我的站点可用/默认文件如下所示:
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 $uri/ /index.php?$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 13:32:26 [错误] 29118#29118:*13 重写或内部重定向循环,同时内部重定向到“/index.php”,客户端:74.105.149.67,服务器:portal.productive.city,请求: "GET /signin/signin HTTP/1.1", 主机: "www.portal.productive.city", referrer: " https://www.portal.productive.city/service-worker.js "
如果我运行 nginx -t 它说我的配置没问题并且成功。
看起来index.php
不存在,/www/Productive-Website/my-app/build
也许它应该是一个.html
或.htm
文件?这会使您的网络服务器尝试呈现,index.php
并且由于它不存在,您将被重定向到index.php
. 如果是这种情况,它会发生在任何路径上。
编辑该文件,使您的位置文件如下所示:
location / {
try_files $uri?$args $uri/ $uri.html?$args /index.html?$args;
}
这意味着,“当收到请求时,搜索匹配的文件$uri OR $uri/ OR $uri.html
,如果这些都不起作用,则渲染/index.html?$args
”。这意味着您的 React 应用程序应该管理 上的所有错误/index.html
,从而使您的应用程序相应地足够。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句