Summary – Host Two Web Apps on Same Server Same Port Different Domain Name Using NGINX.
| NGINX | Host Two Web Apps on Same Server Same Port Different Domain Name Using NGINX.
Two Steps:
- Start Your two or more Web Applications on two different internal ports.
- Setup NGINX Config to combine both the Webapps on same external port.
Procedure
Start Your two or more Web Applications on two different internal ports
![TECH0002-2018.7.19-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-1](http://urbantalks.in/wp-content/uploads/2018/07/TECH0002-2018.7.19-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-1-1024x549.jpg)
One Webapplication listening at one internal port.
![TECH0002-2018.7.19-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-2](http://urbantalks.in/wp-content/uploads/2018/07/TECH0002-2018.7.19-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-2-1024x549.jpg)
Other Webapplication listening at other internal port.
for example in NodeJS you need to append or change this line at the end of app.js file in your code
app.listen(9001, function(){ console.log('Listening on 9001 Port'); });
Setup NGINX Config to combine both the Web Apps on same external port
You can install NGINX on windows using this tutorial.
![TECH0002-2018.7.19-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-4](http://urbantalks.in/wp-content/uploads/2018/07/TECH0002-2018.7.19-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-4-1024x549.jpg)
Configure Nginx
Start Editing at Nginx > Conf > Nginx.conf :
- Create server block for each site.
- Server Blocks should be listenting at same port 80 or 443 but separate server_name.
- Each server block should proxify the respective webapplication port.
- Once done restart the Nginx Service.
The Nginx Code Looks Something Like This.
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; #gzip on; server { listen 000.00.00.0:80 default_server; server_name avenue.in *.avenue.in; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:9001; } } server { listen 000.00.00.0:80; server_name propertyshield.in *.propertyshield.in propertyshield.tk *.propertyshield.tk; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:9002; } } }
Tadda done!!
![TECH0002-2018.1.7-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-0](http://urbantalks.in/wp-content/uploads/2018/07/TECH0002-2018.1.7-Host-Two-Webapps-on-Same-Server-Same-Port-Different-Domain-Name-Using-NGINX-0-1024x549.png)
Done
if you like the tutorial please spread the word aand comment below if you have any questions.