How to run multiple HTTPS web servers from a single server
Hi today we will explore how to run multiple HTTPS web servers from a single sever instance.
you have a home server and have setup a website on the port 80 with your WAN ip
and then you want to run another website but dont have another IP address
what do you do?
It is possible to run multiple web servers with reverse proxy using nginx.
Prerequisits:
1. Nginx
2. Two or more application servers running on one Environment on different ports
consider this code:
server {
listen 80;
server_name site1.com;
location / {
proxy_pass http://localhost:55447;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name site2.site.com;
location / {
proxy_pass http://localhost:8888;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name *.site.com;
location / {
proxy_pass http://localhost:7878;
proxy_set_header Host $host;
}
}
what we are trying to do is listen on the port 80 with nginx and then if the host or server name in the code block matches the site ie our domain - we are simply passing the traffic to the server in the locaion block. with proxy_pass
add the above code in your nginx configuration which is usually at /etc/nginx/nginx.conf
and then setup the DNS for your domain to point to your wan ip and unblock port 80 from your firewall.
you can use cloudflare or certbot for enabling https on all your websites.
Comments
Post a Comment