为什么 nginx 在传递子目录时找不到静态文件

问题描述 投票:0回答:0

我正在使用 nginx 设置代理以将不同的请求重定向到不同的端口或 url,下面列出了两个配置文件:

ingress.conf:

server {
    listen        8876;
    server_name   10.212.38.39;
        
    location ^~ /legislationpinpointextraction {
       proxy_pass http://10.212.38.39:8877;
    }

    location ^~ /legislationcitationextraction {
       proxy_pass http://10.212.38.39:8877;
    }

    location ^~ /datementionextraction {
       proxy_pass http://10.212.38.39:8877;
    }

    location ^~ /autonotegenerator {
       proxy_http_version 1.1;
       proxy_pass https://us-dev.aicat.me/;
    }
 }

出口.conf:

server {
    listen        8877;
    server_name   10.212.38.39;
    location / {
        root /home/jjjia/SDer/;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location ^~ /api/legislationpinpointextraction {
        proxy_pass http://10.212.38.39:6999;
    }

    location ^~ /api/legislationcitationextraction {
        proxy_pass http://10.212.38.39:6999;
    }

    location ^~ /api/datementionextraction {
        proxy_pass http://10.212.38.39:6999;
    }

}
server {
    listen    6999;
    server_name  10.212.38.39;

    location ^~ /api/legislationpinpointextraction {
        add_header 'Access-Control-Allow-Origin' 'http://10.212.38.39:8877';
        add_header 'Access-Control-Allow-Headers' '*';
        add_header 'Access-Control-Allow-Methods' '*';
        proxy_http_version 1.1;
        proxy_pass https://ai-model.dev.caas-common.aicat.me/nlp/legislation-pinpoint-extraction/;
        proxy_redirect off;
    }

    location ^~ /api/legislationcitationextraction {
        add_header 'Access-Control-Allow-Origin' 'http://10.212.38.39:8877';
        add_header 'Access-Control-Allow-Headers' '*';
        add_header 'Access-Control-Allow-Methods' '*';
        proxy_http_version 1.1;
        proxy_pass https://ai-model.dev.caas-common.aicat.me/nlp/legislation-citation-extraction/;
        proxy_redirect off;
    }

    location ^~ /api/datementionextraction {
        add_header 'Access-Control-Allow-Origin' 'http://10.212.38.39:8877';
        add_header 'Access-Control-Allow-Headers' '*';
        add_header 'Access-Control-Allow-Methods' '*';
        proxy_http_version 1.1;
        proxy_pass https://ai-model.dev.caas-common.aicat.me/nlp/date-mention-extraction/;
        proxy_redirect off;
    }
}

有两个问题:

  1. 当我输入http://10.212.38.39:8877/autonotegenerator然后转到https://us-dev.aicat.me,但是浏览器无法找到所有js和css文件,并显示以下错误:

我发现是因为https://us-dev.aicat.me/https://us-dev.aicat.me/autonotegenerator替换了所以静态文件无法生成找到了,但是我该如何更改我的配置来解决这个问题?

  1. 打字http://10.212.38.39:8876/datementionextraction同样的问题发生。

提前谢谢你。

我尝试手动加载静态文件,但仍然找不到它们,因为url已更改。

nginx proxy nginx-config
© www.soinside.com 2019 - 2024. All rights reserved.