Reverse proxy for multiple domains

Francis Daly francis at daoine.org
Tue May 22 20:00:42 UTC 2018


On Mon, May 21, 2018 at 01:57:07PM +0000, Mik J via nginx wrote:

Hi there,

> I would like to know what is the best practice to setup a web proxy.
> 
> I do it like this
> - 1 virtual host per application on the reverse proxy and the proxy_pass points to one IP+path
> - 1 virtual host (default) for all application on the backend server but one location stanza per application
> 
> The problem is that I meet many problems with installation of application: magento, glpi, etc

If the problem is *installing* the applications, that might be a
question for the application list. If the problem is *reverse-proxying*
the applications, that might be a question for the nginx list.

It is good to be clear about what the specific problem you are seeing is.

> Is it the correct way to do it ?

It is usually easiest if the front-end /prefix and the back-end /prefix
are identical.

So if the back-end application is happy being installed at /application1/,
then the front-end should reverse-proxy from frontend/application1/ to
upstream1/application1/. In that case, multiple applications could all be
on the same frontend server{}, or on different ones. If different ones,
then it can redirect from / to /application1/ if that is simplest.

If the back-end application insists on being installed at /, then the
front-end should reverse-proxy from frontend/ to upstream2/. In that case,
you will probably need multiple frontend server{}s; one for each similar
application.

> location ^~ / {
> proxy_pass        http://10.1.1.10:80/app/application1/;

"/" to "/app/application1/" is possible, but it is easy for things to
go wrong.

For example: if the application returns a link to
/app/application1/file, the next request to the upstream might be to
/app/application1/app/application1/file, which may not work as desired.

> server {
> listen 80 default_server;

This config looks generally right, if it is the correct way to install
this application...

> server_name _;
> index index.html index.htm index.php;
> root /var/www/htdocs;
> location ^~ /app/application1 {
> root /var/www;
> index index.php;
> location ~ \.php$ {

Note, though, that:

> root          /var/www;
> try_files $uri =404;

those two lines...

> fastcgi_pass  unix:/run/php-fpm.application1.sock;

> fastcgi_split_path_info ^(.+\.php)(/.+)$;
> fastcgi_index  index.php;

and those two lines, probably do not do anything useful here.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list