Proxy pass and URL rewrite with upstream

M. Rodrigo Monteiro falecom at rodrigomonteiro.net
Thu Dec 21 14:09:11 UTC 2017


Hi!

I'm new to nginx and I need you help do setup the way I need.
The server is nginx-1.12.2-1.el7.x86_64 (rpm) on CentOS 7.2 64.

My scenario is: all my systems are http://systems.ltda.local/NAME
(systems.ltda.local is nginx as reverse proxy)
The nginx must rewrite (or proxy, or whatever) to 4 Apaches servers
responding with the virtual host as NAME.ltda.local and the URL in the
browser must not change.

When a user types http://systems.ltda.local/phpmyadmin it goes to
nginx and nginx proxy to apache on the URL phpmyadmin.ltda.local but
the URL keeps the same on the browser.


My config:

# cat upstream.conf
upstream wpapp {
  server XXX.XXX.XXX.XXX:80 fail_timeout=60;
  server XXX.XXX.XXX.XXX:80 fail_timeout=60;
  server XXX.XXX.XXX.XXX:80 fail_timeout=60;
  server XXX.XXX.XXX.XXX:80 fail_timeout=60;
}

# cat systems.ltda.local.conf

server {
  listen 80;
  server_name systems.ltda.local;
  access_log /var/log/nginx/systems.ltda.local_access.log;
  error_log /var/log/nginx/systems.ltda.local_error.log;

location /phpmyadmin {
  proxy_pass http://wpapp/;
  sub_filter "http://systems.ltda.local/phpmyadmin"
"http://phpmyadmin.ltda.local";
  sub_filter "http://systems.ltda.local/phpmyadmin/" "http://phpmyadmin.ltda/";
  sub_filter_once off;
  }

}

With this configuration, only works the URL with a trailing slash
"http://systems.ltda.local/phpmyadmin/" and not
"http://systems.ltda.local/phpmyadmin".

Best regards,
Rodrigo.


More information about the nginx mailing list