V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
tyit
V2EX  ›  NGINX

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

  •  
  •   tyit · Mar 31, 2021 · 1266 views
    This topic created in 1861 days ago, the information mentioned may be changed or developed.
    有个 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 replies    2021-10-27 05:54:18 +08:00
    szpunk
        1
    szpunk  
       Oct 27, 2021
    location ~ ^/abc .*\.(js|css|jpg|jpeg|gif|png|ico|pdf|txt)$ {
    if ($request_uri ~* "^/icenter/(.*)$") {
    proxy_pass http://10010/$1;
    }
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   810 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:14 · PVG 06:14 · LAX 15:14 · JFK 18:14
    ♥ Do have faith in what you're doing.