webman nginx配置 /访问静态目录,/api访问webman,怎么配置nginx

ontheway

静态文件在/frontend/webman目录
webman应用监听8080端口
域名:webman.v3.com

例如访问:http://webman.v3.com/ 实际访问/frontend/webman/index.html
例如访问:http://webman.v3.com/api/user/info 访问webman应用User控制器的info方法

问题已解决:

我知道原因了,我用的是手册里面的nginx代理示例:

upstream webman {
    server 127.0.0.1:8787;
    keepalive 10240;
}

server {
  server_name webman.v3.com;
  listen 80;
  access_log off;

  location /api/ {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      if (!-f $request_filename){
          proxy_pass http://webman;
      }
  }

    location / {
        root /frontend/webman;
    }
}

问题就出在这一句:

proxy_pass http://webman;

需要在后面加上斜杠就OK了:

proxy_pass http://webman/;

如果不加就会把/api/带上,最终url变成http://127.0.0.1:8787/api/

1565 3 3
3个回答

nitron
location /api/ {
    proxy_pass http://127.0.0.1:8080/;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location / {
    root /frontend/webman;
}
  • ontheway 2022-07-15

    这样不行,访问http://webman.v3.com/api/返回404,应该是webman不认识/api,要是搞成多应用,估计它就可以识别了,其中一个应用就是api

  • nitron 2022-07-15

    把它换下位置,我编辑了

  • ontheway 2022-07-15

    一样的,不行

  • nitron 2022-07-15

    不好意思少打了个反斜杠

  • ontheway 2022-07-15

    一样的,不行。我估计要webman支持才行

ontheway

目前只找到了一个方法,那就是使用多应用,在app下面增加一个api应用即可

  • 暂无评论
nitron

...复制太快了,刚刚
截图
proxy_redirect 那个去掉

年代过于久远,无法发表回答
🔝