Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs nginx将所有URL重定向到index.html_Reactjs_Redirect_Nginx_React Router - Fatal编程技术网

Reactjs nginx将所有URL重定向到index.html

Reactjs nginx将所有URL重定向到index.html,reactjs,redirect,nginx,react-router,Reactjs,Redirect,Nginx,React Router,我正在尝试根据以下指南配置nginx服务器: 但看起来好像不起作用,我正在尝试使用我的nginx docker图像。所以 Dockerfile: 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

我正在尝试根据以下指南配置nginx服务器:

但看起来好像不起作用,我正在尝试使用我的nginx docker图像。所以

Dockerfile:

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;
    }
}
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;
    }
}
试图打开一个不存在的页面

获取本地主机/somestuppidrandomurl

nginx错误日志:

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;
    }
}
[error]7#7:*3 open()“/usr/share/nginx/html/sometStupidrandomURL”失败(2:没有这样的文件或目录),客户端:172.17.0.1,服务器:localhost,请求:“GET/sometStupidrandomURL HTTP/1.1”,主机:“localhost”


提前感谢。

在深入搜索之后,我意识到问题是,
/etc/nginx/conf.d/
路径上还有一个default.conf文件,该配置覆盖了我的配置

我只是将Dockerfile第3行替换为

复制/vhosts.conf/etc/nginx/conf.d/default.conf
并像魔术一样工作