【问题标题】:Docker nginx can't get single page application to runDocker nginx 无法运行单页应用程序
【发布时间】:2021-01-22 20:55:46
【问题描述】:

我正在使用以下 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 并根据documentation 猜测它进入http,但是当路由不指向文件时它不服务器index.html。

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

【问题讨论】:

    标签: docker nginx single-page-application


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2016-11-29
      • 2019-11-24
      • 2017-12-25
      • 2020-07-17
      • 2021-08-12
      • 2020-12-30
      • 1970-01-01
      • 2020-02-16
      相关资源
      最近更新 更多