How to Configure Nginx to be gateway to serve Multiple Websites

I have a domain name domainname.com using centos7.
I have subdomains where differents applications run. For example:

https://app1.domainname.com
https://app2.domainname.com
https://app3.domainname.com
https://nginx.domainname.com

app1, app2, app3 and nginx are four differents servers.
app1, app2 and app3 are accessible from the internet.

What I want is to access all my applications from the internet via https://nginx.domainname.com. For example:

https://nginx.domainname.com/app1 → to serve https://app1.domainname.com
https://nginx.domainname.com/app2 → to serve https://app2.domainname.com
https://nginx.domainname.com/app3 → to serve https://app3.domainname.com

To achieve that, I have configured the reverse proxy in the https://nginx.domainname.com server to access app1 app2 app3 via the https://nginx.domainname.com server.
I modified the nginx.conf file of the https://nginx.domainname.com server as follows:


http
{

server
{

serveur_name nginx.domainname.com

location /app1{
proxy_set_header host $proxy_host;
proxy_pass app1.domainname.com; }

location /app2{
proxy_set_header host $proxy_host;
proxy_pass app2.domainname.com; }

location /app3{
proxy_set_header host $proxy_host;
proxy_pass app3.domainname.com; }

}
}

but I can’t access apps through the https://nginx.domainname.com server

I cannot find a Way to achieve this after many try… I get error like server https://nginx.domainname.com is not accessible

Can you help me with the different steps to follow to achieve this?

Hi Android_androod,

Welcome to our forums.

At first glance of your configuration parts there is a typo:

Which should be server_name I suppose. I would suggest you always validate your nginx configuration with something like:

nginx -c /etc/nginx/nginx.conf -t

And do so before applying the changes. The error message suggests that your nginx server can’t run, which can be caused by a simple typo in the configuration. I also suggest you setup reverse proxy to a single application first, and add more after that works flawlessly.

You may want to check our guide on nginx reverse proxy for reference.