K8S部署saber-web静态资源访问不到,直接报404

Blade 未结 1 619
957764092
957764092 剑者 2021-10-08 11:27

一、该问题的重现步骤是什么?

  1. nginx 配置


  2. 
    user  root;
    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;
    
        upstream gateway {
            server blade-gateway;
        }
    
    
        server {
          listen       80;
          server_name  hwt.stoneboss.vip;
          root         /usr/share/nginx/html;
    
          location / {
    
          }
    
          location ^~/api {
               proxy_set_header Host $host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_buffering off;
               rewrite ^/api/(.*)$ /$1 break;
               proxy_pass http://gateway;
          }
          location /image/ {
                  root  /static/file;
                 autoindex on;
             }
          location /file/ {
                  root  /static/file;
                 autoindex on;
            }
        }
    
    
    }

2. dockerfile打包配置

FROM nginx:stable-alpine-perl

RUN rm -f /etc/nginx/nginx.conf \
    && rm -f /etc/nginx/conf.d/default.conf \
    && mkdir -p /static/file/image \
    && mkdir -p /static/file
COPY docker/nginx.k8s.conf /etc/nginx/nginx.conf

EXPOSE 80

COPY ./dist /usr/share/nginx/html

ENTRYPOINT ["nginx", "-g", "daemon off;"]

3.

image.png

图片地址访问:http://hwt.stoneboss.vip/image/2-2021100802423139.jpg  

直接报404

image.png

二、你期待的结果是什么?实际看到的又是什么?


三、你正在使用的是什么产品,什么版本?在什么操作系统上?


四、请提供详细的错误堆栈信息,这很重要。


五、若有更多详细信息,请在下面提供。

1条回答
  • 2021-10-09 00:25

    看你的截图,图片路径似乎不在 /usr/share/nginx/html 目录下,你指向错了,自然就404了

    0 讨论(0)
提交回复