NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ly61
V2EX  ›  NGINX

关于 nginx 配置访问静态资源的问题

  •  
  •   ly61 · Feb 2, 2021 · 3051 views
    This topic created in 1926 days ago, the information mentioned may be changed or developed.

    tomcat 的端口号 8080 访问的只是为“ip:8080/web/a/c” 现在需要配置访问“ip:8080/web/a/c”时候访问“ip:12000/static/web/a/c”这个地址。 请问该怎么配置啊?

    9 replies    2021-02-03 09:02:11 +08:00
    eason1874
        1
    eason1874  
       Feb 2, 2021
    首先确认 “ip:12000/static/web/a/c” 可访问,然后在 ip:8080 server 加入配置如下:

    location /web/a/c {
    proxy_pass http://ip:12000/static$request_uri;
    }

    注意后端是 http 还是 https,如果不要查询参数可以把 $request_uri 换成 $uri,其它反代配置自行补充
    ly61
        2
    ly61  
    OP
       Feb 2, 2021
    @eason1874 好嘞,谢谢,我试试
    lemon94
        3
    lemon94  
       Feb 2, 2021
    非后端,貌似有个叫软链接的不知道可不可以
    wfczdmy16129
        4
    wfczdmy16129  
       Feb 2, 2021
    location /web/a/c {
    alias {path}/static/web/a/c
    }

    proxy_pass 是转发请求 不太建议
    ly61
        5
    ly61  
    OP
       Feb 2, 2021
    @wfczdmy16129 好的,我试下,其实这些我都试了下,但是都不管用
    meepo3927
        6
    meepo3927  
       Feb 2, 2021
    8080 和 12000 是同一个主机用 4 楼的方法,

    8080 和 12000 是不同主机,用 1 楼的方法。
    feitxue
        7
    feitxue  
       Feb 2, 2021
    你到底设置 tomcat 还是 nginx
    tomcat 的话,java 里面设置转发
    nginx 的话,看楼上的回复即可.
    ly61
        8
    ly61  
    OP
       Feb 3, 2021
    @meepo3927 okok
    ly61
        9
    ly61  
    OP
       Feb 3, 2021
    @feitxue 嗯嗯
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1509 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 16:45 · PVG 00:45 · LAX 09:45 · JFK 12:45
    ♥ Do have faith in what you're doing.