反应总是重定向到主页

时间:2018-01-10 15:19:15

标签: reactjs redirect nginx

首先,我有新的反应,所以我还在了解它。

如果我从另一个域/站点创建超链接以响应localhost上的应用程序,例如http://localhost:8089/foo/bar,我就会遇到此问题。它会直接显示正确的页面,但是如果我使用https协议(例如https://example.com/foo/baz)从其他域/站点到公共域创建超链接,它总是会重定向到主页(https://example.com/

我能做些什么让它直接进入https://example.com/foo/baz。我在nginx web服务器上使用这个重定向设置运行反应,它适用于php,django等,但不会运行反应。

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com;
    return 301 https://$server_name$request_uri;
    root /home/[path to dist folder]/web/app/dist;
    index index.html index.htm;

}

仅供参考,感谢您使用webpack构建反应应用程序,并提前感谢

2 个答案:

答案 0 :(得分:0)

我遇到的问题是:

"return 301 https://$server_name$request_uri;"

您应该替换它:

"return 301 https://$server_name/$request_uri;"

答案 1 :(得分:0)

我已经设法为文件添加正确的配置。

应该是这样的

server {
    ...
    location / {
        ...
        try_files $uri $uri/ /index.html;
    }
    ...

}

感谢所有人的帮助

相关问题