首页 > 解决方案 > NGINX - Spring Boot 应用程序(“/etc/nginx/html/index.html”未找到)

问题描述

所以我有我想放在 nginx 后面的 spring boot 应用程序,问题是我在访问 localhost 时连接被拒绝。

我的 nginx 配置如下所示:

    server {

    listen 80;
    server_name workaround;
    charset utf-8;
    access_log off;


    location / {
       proxy_pass http://172.19.0.3:8080/workaround;
       proxy_set_header X-Real-IP         $remote_addr;
       proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Host  $host;

     }
}

我正在运行的内容:

在此处输入图像描述

访问 localhost 时我得到的响应

在此处输入图像描述

404 未找到。当它在我的 docker compose 文件中时,它怎么会寻找一些 etc/nginx/html/index: 在此处输入图像描述

  nginx:
    container_name: workaround-nginx
    image: nginx:1.15.12-alpine
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    depends_on:
      - workaround

我的配置有什么问题?如何正确访问我的 SB 应用程序?

标签: springspring-bootdockernginx

解决方案


好的,我想通了,我什至设法修复它,以便它与具有哈希前缀的资源一起使用:

events {
  worker_connections 1024;
}

http {

  server {
        listen 80;
        charset utf-8;
        access_log off;
        try_files $uri $uri/ =404;

        location / { #this still has to be here, otherwise i get ISE
            proxy_pass http://workaround:8085/;
        }

        location ^~ { #this thing fixes hashes and resources
            proxy_pass              $scheme://workaround:8085/$request_uri;
            proxy_redirect  off;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        Host $http_host;
            expires 30d;
         }
    }


}

推荐阅读