【问题标题】:How to make routes work when deploying react app with nginx docker使用 nginx docker 部署 react 应用程序时如何使路由工作
【发布时间】:2019-09-18 14:12:57
【问题描述】:

尝试使用 nginx docker 部署 react 应用程序,但无法使子文件夹正常工作。在这里阅读了所有非常相似案例的建议,但仍然没有结果。我有 docker-compose 容器和 nginx 运行自定义配置和端口映射 9999:80。在尝试直接访问任何子文件夹时,我从 nginx 得到 404。附加我的 nginx 配置。

nginx 容器尝试获取 /statistics 子文件夹的日志中的内容:


frontend_1  | 172.21.0.1 - - [18/Sep/2019:14:01:27 +0000] "GET /statistics HTTP/1.1" 404 556 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" "-"
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 {
        root /usr/share/nginx/html;
        location / {
            try_files $uri /index.html;
        }
    }
}

【问题讨论】:

    标签: docker nginx


    【解决方案1】:

    在我的例子中,它有助于将监听端口从默认 80 更改为 8080

    server {
        listen 8080;
        root /usr/share/nginx/html;
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-30
      • 2021-03-22
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多