shanghai1943
V2EX  ›  问与答

求教一个 web 应用类型导致的 NGINX404 问题

  •  
  •   shanghai1943 · Sep 9, 2021 · 1333 views
    This topic created in 1791 days ago, the information mentioned may be changed or developed.

    远程机器上部署了 skywalking 链路追踪服务,在浏览器通过域名访问这个服务是正常的,页面内点击了 [追踪] 这个板块,页面正常切换到了这个板块,然后浏览器的 URL 也加上了 /trace 的后缀,但是如果直接刷新的话,会出现 404 的情况。

    NGINX 配置如下

    location / { proxy_pass http://localhost:1234; }

    看起来像是一个单应用通过 js 切换页面然后修改浏览器地址。本人前端小白,瞎猜测的。

    想问下这种类型的 web 应用该如何配置 NGINX 访问。

    感谢。

    6 replies    2021-09-10 16:02:04 +08:00
    ashes1122
        1
    ashes1122  
       Sep 10, 2021
    location ~/trace {
    proxy_pass http://localhost:1234;
    }
    abccccabc
        2
    abccccabc  
       Sep 10, 2021
    楼主,你的意思是页面使用了 js 的路由,页面 url 地址只能点击,不能刷新对吧?
    试下这个:
    location / {
    try_files $uri $uri/ /index.html;
    }
    shanghai1943
        3
    shanghai1943  
    OP
       Sep 10, 2021
    @abccccabc #2 似乎不行。因为这个 web 应用是通过 ip:port 来访问的。这种配置方式应该是针对那种有 root /path/to/static/html 的有用的吧。
    shanghai1943
        4
    shanghai1943  
    OP
       Sep 10, 2021
    @ashes1122 #1 这个可能只解决了 /trace 的问题,还有另外的页面比如 /a /b 之类的不能一一枚举。
    dengshen
        5
    dengshen  
       Sep 10, 2021 via iPhone
    @shanghai1943 举一反三把固定的那个换成星号啊。。。
    shanghai1943
        6
    shanghai1943  
    OP
       Sep 10, 2021
    @dengshen 额。恕我愚钝。貌似试了

    location ~/* {

    proxy_pass http://localhost:1234;

    }

    这样也不行。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5507 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:52 · PVG 15:52 · LAX 00:52 · JFK 03:52
    ♥ Do have faith in what you're doing.