【问题标题】:react.js app showing 404 when refreshing in nginx server configured on macos在 macos 上配置的 nginx 服务器中刷新时 react.js 应用程序显示 404
【发布时间】:2021-06-02 13:15:06
【问题描述】:

我已经为 nginx 配置了 MacOS,并在其上部署了我的 react js 应用程序,它已成功部署并运行,但是当我重新刷新任何页面时,它显示 404 not found。

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8080;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen       8080 default_server;
        server_name  TESTAPP;
        root  /var/www/TESTAPP;
        index index.html index.htm;      
        location / {
            root /var/www/TESTAPP/static;
            index  index.html index.htm;
            try_files $uri /index.html$is_args$args =404;
        }
    }
    include servers/*;
}

【问题讨论】:

  • 缺少一些细节。你能告诉我们nginx配置吗
  • 这应该会有所帮助 - stackoverflow.com/questions/43555282/…
  • @Shyam 我也试过,但没用。
  • @jibeeeeee 我在问题描述中添加了配置。
  • 配置文件看起来正常。 刷新时出现404是什么意思?那么所有页面都可以第一次访问?

标签: reactjs nginx


【解决方案1】:

如果以下对你有用,你可以试试吗?

这是我用于 SPA 的。

server {
        listen 8080 default_server;

        root  /var/www/TESTAPP;
        index index.html index.htm;   

        server_name TESTAPP;

        location / {
                try_files $uri $uri/ =404;
        }
}

【讨论】:

    猜你喜欢
    • 2017-09-19
    • 2017-05-16
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 2019-07-31
    • 2021-04-09
    相关资源
    最近更新 更多