Welcome! Log In Create A New Profile

Advanced

Reverse proxy for multiple domains

Posted by Mik J via nginx 
Mik J via nginx
Reverse proxy for multiple domains
August 10, 2017 11:20PM
Nginx: 1.10.2


Hello,

I'm tryging to get reverse proxy working with multiple domains


I have application1.org and application2.org.


The client requesting these URLs, arrives one the reverse proxy.

On this reverse proxy I have a virtual host which looks like that

server {

listen 80;

server_name application1.org;

access_log /var/log/nginx/application1.org.access.log;

error_log /var/log/nginx/application1.org.error.log;

....


location ^~ / {

proxy_pass http://10.1.1.10:80/app/application1/;

proxy_redirect off;

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;

proxy_set_header X-Forwarded-Proto $scheme;

}

And another virtual host for application2 which is similar with

proxy_pass http://10.1.1.10:80/app/application2/;


The server behind the reverse proxy is the same right now



On the web server behind the proxy I just have one virtual host which is the default one

server {

listen 80 default_server;

server_name _;

index index.html index.htm index.php;

root /var/www/htdocs;


location ^~ /app/application1 {

root /var/www;

index index.php;

location ~ \.php$ {

root /var/www;

try_files $uri =404;

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

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

location ^~ /app/application2 {
root /var/www;
index index.php;
location ~ \.php$ {
root /var/www;
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm.application2.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}

Questions:

1) Is it the right way to do this ?

2) When I access the application from Internet using application1.org, I am redirected to application1.org/app/application1 I don't know why. And I have to add one more section on the reverse proxy
location ^~ /app/application1 {
proxy_pass http://10.1.1.10:80/app/application1/;
proxy_redirect off;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
Is there a better way to do it ?

Thank you
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: Reverse proxy for multiple domains
August 17, 2017 09:40PM
On Thu, Aug 10, 2017 at 09:17:14PM +0000, Mik J via nginx wrote:

Hi there,

> I have application1.org and application2.org.
>
> The client requesting these URLs, arrives one the reverse proxy.
>
> On this reverse proxy I have a virtual host which looks like that
>
> server {
> server_name application1.org;
> location ^~ / {
> proxy_pass http://10.1.1.10:80/app/application1/;
> }
>
> And another virtual host for application2 which is similar with
>
> proxy_pass http://10.1.1.10:80/app/application2/;
>
>
> The server behind the reverse proxy is the same right now

> 1) Is it the right way to do this ?

I think that trying to reverse-proxy an application at a different part
of the url tree to where the app thinks it is installed, is difficult.

So if application1 believes that it is installed at /app/application1,
I would suggest to expose that to the world. (Or: if you want the world
to see it at /, then configure the internal server so that it is at /
there too.)

Then your external config is mostly just "proxy_pass
http://10.1.1.10:80;";, possibly with "location = / { return 301
/application/app1/; }"

The *internal* config could probably have one server{} for each
application as well.

> 2) When I access the application from Internet using application1.org, I am redirected to application1.org/app/application1 I don't know why. And I have to add one more section on the reverse proxy

> Is there a better way to do it ?

I'm not sure why that extra section is necessary, unless the "..." part
of your config is important.

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Mik J via nginx
Re: Reverse proxy for multiple domains
August 18, 2017 09:10AM
Thank you Francis for your answer
Actually is does this with a simple index.html page# cat index.htmlTEST
What would you do if you had ?
CLIENT <-> INTERNET <->Reverse_Proxy<->Web_ServerOn de web server I just use one default virtual host with multiple sections. Thats because the pages are called by the reverse proxy server like http://10.1.1.10:80/app/application1/; and it can't use a FQDN because it's in a private adressing
Is there a way that the reverse proxy connects to 10.1.1.10 but pretend the GET/POST queries use application1.org ?

I'd prefer my application would be accessible by www.application1.org than www.application1.org/app/application1 like right now



Le Jeudi 17 août 2017 21h35, Francis Daly <francis@daoine.org> a écrit :


On Thu, Aug 10, 2017 at 09:17:14PM +0000, Mik J via nginx wrote:

Hi there,

> I have application1.org and application2.org.
>
> The client requesting these URLs, arrives one the reverse proxy.
>
> On this reverse proxy I have a virtual host which looks like that
>
> server {
> server_name application1.org;
> location ^~ / {
> proxy_pass        http://10.1.1.10:80/app/application1/;
> }
>
> And another virtual host for application2 which is similar with
>
> proxy_pass http://10.1.1.10:80/app/application2/;
>
>
> The server behind the reverse proxy is the same right now

> 1) Is it the right way to do this ?

I think that trying to reverse-proxy an application at a different part
of the url tree to where the app thinks it is installed, is difficult.

So if application1 believes that it is installed at /app/application1,
I would suggest to expose that to the world. (Or: if you want the world
to see it at /, then configure the internal server so that it is at /
there too.)

Then your external config is mostly just "proxy_pass
http://10.1.1.10:80;";, possibly with "location = / { return 301
/application/app1/; }"

The *internal* config could probably have one server{} for each
application as well.

> 2) When I access the application from Internet using application1.org, I am redirected to application1.org/app/application1 I don't know why. And I have to add one more section on the reverse proxy

> Is there a better way to do it ?

I'm not sure why that extra section is necessary, unless the "..." part
of your config is important.

    f
--
Francis Daly        francis@daoine.org


_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login