nginx将所有网址重定向到index.html

时间:2018-08-27 22:08:33

标签: reactjs redirect nginx react-router

我正在尝试根据以下指南配置nginx服务器:https://gkedge.gitbooks.io/react-router-in-the-real/content/nginx.html

但是看起来不起作用,我正在尝试将其与nginx的docker镜像一起使用。所以,

Dockerfile:

    Iterator<Entity> it = entityList.iterator();
    while (it.hasNext()) {
        Entity entity = it.next();

        if (...) {
            it.remove();
        }
    }

vhosts.conf:

FROM nginx:1.11.5

COPY /dist /usr/share/nginx/html
COPY /vhosts.conf /etc/nginx/conf.d/vhosts.conf

试图打开一个不存在的页面。

server { listen 80 default_server; server_name /usr/share/nginx/html; root /usr/share/nginx/html; index index.html index.htm; location ~* \.(?:manifest|appcache|html?|xml|json)$ { expires -1; # access_log logs/static.log; # I don't usually include a static log } location ~* \.(?:css|js|json)$ { try_files $uri =404; expires 1y; access_log off; add_header Cache-Control "public"; } # Any route containing a file extension (e.g. /devicesfile.js) location ~ ^.+\..+$ { try_files $uri =404; } # Any route that doesn't have a file extension (e.g. /devices) location / { try_files $uri $uri/ /index.html; } }

nginx错误日志:

GET localhost/somestupidrandomurl

谢谢。

1 个答案:

答案 0 :(得分:0)

经过深入的搜索,我发现问题出在/etc/nginx/conf.d/路径下还有一个default.conf文件,并且配置覆盖了我的配置。

我只是将Dockerfile第3行替换为

COPY /vhosts.conf /etc/nginx/conf.d/default.conf就像魔术一样。