Proxy pass and URL rewrite with upstream

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Proxy pass and URL rewrite with upstream

M. Rodrigo Monteiro
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.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Proxy pass and URL rewrite with upstream

Aziz Rozyev
Hi

create 4 separate upstreams for each of these apaches,

create 4 locations, within each location block proxy_pass to appropriate upstream.

avoid using sub_filters, they are mostly forrewriting bodies of html documents.

http {

# for phpadmin
upstream phpadminup {
   server phpadmin.ltda.local:80;
}

upstream whateverup {
   server whatevername.ltda.local:80;
}

server {
   listen 80;

   location /phpadmin/ {
      proxy_pass http://phpadmin;
   }
   
   location /whatevername/ {
      proxy_pass http://whatever;
   }

   ...

}



}
br,
Aziz.





> On 21 Dec 2017, at 17:09, M. Rodrigo Monteiro <[hidden email]> wrote:
>
>
>  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;
>  }

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Proxy pass and URL rewrite with upstream

Zhang Chao
In reply to this post by M. Rodrigo Monteiro
Hello!

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

What do you mean of it doesn’t work with the URL without the trailing slash? 
Does the backend Apache server just returns 404?

The URL path that your nginx passes to the backend will be:



_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx