V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
tyit
V2EX  ›  NGINX

嵌套 nginx 获取不到静态资源导致访问出 404 ?

  •  
  •   tyit · 2021-03-31 17:49:10 +08:00 · 718 次点击
    这是一个创建于 1093 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有个 vue 项目,部署到了内网,外网也是一个 nginx,是别人家的,借用做入口。入口这个 nginx 不给放静态资源。

    访问入口的时候,加载资源不到,导致访问出 404 。有什么办法,能实现访问入口 nginx 的时候去后面的 nginx 获取静态资源嘛?

    入口 nginx 配置

    location ^~ /abc {
    proxy_pass http://10010/abc;
    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 $host:$server_port;
    proxy_set_header X-Forwarded-Proto "https";
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Real-IP $remote_addr;
    }

    加上这个可以加载到后端的静态资源,但是入口的静态网站,静态资源也会 proxy_pass http://10010/$1;
    入口哪有个静态网站,不给这么配置。

    #location ~ .*\.(js|css|jpg|jpeg|gif|png|ico|pdf|txt)$ {
    # if ($request_uri ~* "^/icenter/(.*)$") {
    # proxy_pass http://10010/$1;
    # }
    # }


    后面的 nginx 配置

    server {

    listen 80;
    server_name _;
    root /usr/share/nginx/html;

    include /etc/nginx/default.d/*.conf;

    location /abc {

    alias /usr/share/nginx/html/;

    }
    1 条回复    2021-10-27 05:54:18 +08:00
    szpunk
        1
    szpunk  
       2021-10-27 05:54:18 +08:00
    location ~ ^/abc .*\.(js|css|jpg|jpeg|gif|png|ico|pdf|txt)$ {
    if ($request_uri ~* "^/icenter/(.*)$") {
    proxy_pass http://10010/$1;
    }
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3244 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:06 · PVG 20:06 · LAX 05:06 · JFK 08:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.