Docker nginx 无法获取单页应用到 运行

Docker nginx can't get single page application to run

我正在使用以下 docker 命令:

docker run --name spa \
    -v "$PWD/build":/usr/share/nginx/html:ro \
    -v "$PWD/nginx.conf":/etc/nginx/nginx.conf:ro -d -p 8080:80 nginx

然后我可以打开 localhost:8080 并获取索引,点击链接工作,因为导航是在客户端完成的,但然后刷新 localhost:8080/en 会给我一个来自 nginx 的 404。 "$PWD/nginx.conf" 是:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    server {
      listen 80;
      root /usr/share/nginx/html;
      gzip on;
      gzip_types text/css application/javascript application/json image/svg+xml;
      gzip_comp_level 9;
      etag on;
      location / {
        try_files $uri $uri/ /index.html;
      }
      location /static/ {
        add_header Cache-Control max-age=31536000;
      }
      location /index.html {
        add_header Cache-Control no-cache;
      }
      location /config.json {
        add_header Cache-Control no-cache;
      }
    }
}

我得到了服务器部分表单 here and guess it goes in http according to the documentation,但是当路由不指向文件时它不会服务器 index.html。

./build 中有一个文件 index.html 在根路径上提供。

我删除了配置中的 include /etc/nginx/conf.d/*.conf;,现在可以使用了。