How do I rewrite URLs in a proxy response in NGINX

前端 未结 3 1273
庸人自扰
庸人自扰 2020-11-28 19:42

I\'m used to using Apache with mod_proxy_html, and am trying to achieve something similar with NGINX. The specific use case is that I have an admin UI running in Tomcat on

3条回答
  •  渐次进展
    2020-11-28 20:33

    You can use the following nginx configuration example:

    upstream adminhost {
      server adminhostname:8080;
    }
    
    server {
      listen 80;
    
      location ~ ^/admin/(.*)$ {
        proxy_pass http://adminhost/$1$is_args$args;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
      }
    }
    

提交回复
热议问题