刷新React应用程序,在Ubuntu上获取NGINX 404错误
好的,所以每次我在不是根/主页上的页面上刷新我的React应用程序时,我会收到404错误。我已经做了很多挖掘,发现我应该更改我的nginx配置文件。唯一的问题是对其他所有人都有用的变化对我来说绝对没有做任何事情。
文件路径 - /etc/nginx/stites -abailable/default
我的nginx配置文件看起来像这样 -
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.html;
}
我什至尝试在/var/www/html上添加root目录;毫不奇怪,它行不通。
基于我所看到的一切都应该起作用...那为什么不呢?这现在是React路由器问题吗?任何帮助都将非常感谢,我对这个问题感到不安。如果需要更多信息,我可以很乐意提供它,我敢肯定,不确定还有什么原因是该问题的原因。
Alright so every time I refresh my React app on a page that isn't the root/home page I get a 404 error. I've already done a lot of digging and found that I'm supposed to change my nginx config file. The only issue is this change that's working for everyone else is doing absolutely nothing for me.
File path - /etc/nginx/sites-available/default
My nginx config file looks like this -
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.html;
}
I've even tried adding a root directory at /var/www/html; To no surprise it didn't work.
Based off everything I've seen this SHOULD work... so why isn't it? Is this now a React Router issue or something? Any help would be greatly appreciate, I'm beyond stumped with this issue. If more information is needed I can gladly provide it, I'm sure not sure what else could be the cause of this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过数小时与nginx.config弄乱后,我终于解决了我的问题。
目录 - /etc/nginx/sites -abailable |然后 - sudo nano默认
对我有用的东西 -
我的根仍设置为 - root/var/www/html,
对于任何遇到麻烦的人都可以完全清除所有Nginx文件并重新安装清洁的板岩。我认为我的错误是我添加了“ nginx.conf”文件,这最终导致了其他配置文件“默认”。因此,总而言之,仅触摸默认配置文件,然后将nginx.conf作为默认值。
After hours of messing around with the nginx.config I finally solved my issue.
Directory - /etc/nginx/sites-available | then - sudo nano default
What worked for me -
My root is still set to - root /var/www/html
For anyone having troubles try completely purging all nginx files and reinstalling for a clean slate. What I think was wrong for mine was I had added to the "nginx.conf" file and that ended up causing complications with the other config file "default." So all in all, only touch the default config file, and leave nginx.conf as default.