0

I want to run multiple sites on the same domain, using nginx, but on different ports and want them all to use SSL

Let's say,

I have two sites siteone.com and sitetwo in the directory /var/www/ as follows:

/var/www/siteone.com/ /var/www/sitetwo/ 

I want to host siteone.com on the domain https://siteone.com and sitetwo on the same domain but on a different port, say https://siteone.com:8080

Note: having SSL on both sites is important.

It might sound like I'm over engineering stuff here, but I still want to know if it is possible to do so? I'm using nginx web server. What would my nginx conf file look like?

I had tried using the following but it didn't work:

server { listen 443; server_name siteone.com; root /var/www/; # ssl stuff here } server { listen 8080; server_name sitetwo; root /var/www/; # ssl stuff here } server { listen 80; server_name siteone.com; return 301 https://$host$request_uri; } 
3
  • You should set the server_name for site_two also to siteone.com and let nginx do the mapping based on the port. What does "it didn't work" mean? Please add error messages and log file entries to your post. Commented Jun 13, 2018 at 11:41
  • A few more details would be helpful - nginx logs for example. Commented Jun 13, 2018 at 13:47
  • Thank you so much for the response @Sven . I think I figured out the problem. And I have posted a solution. Commented Jun 14, 2018 at 6:07

1 Answer 1

1

So here are a few pointers for anyone coming here:

As pointed out correctly by @Sven in this comment, I should've written siteone.com instead of sitetwo in the 2nd server block in my nginx.conf mentioned above. But the problem doesn't end there. The site I had set up contains user login, and hence I had installed fail2ban on the server. Because of this, whenever I used to login to both the sites (same domain different ports) simultaneously in the same browser, fail2ban would block my IP. This led me to believe it was an nginx.conf issue which was the problem.

Why would fail2ban block me: Let's assume the following scenario,

I log into siteone.com in tab 1 of my browser. Next I open tab 2 in the same browser and log into siteone.com:8080. Because of this siteone.com login in tab 1 is invalidated. However, tab one is still trying to connect to the server in the background using incorrect authentication and because it is happening continuously fail2ban blocks out my IP address.

Reason why I think what I mentioned above was the issue: If I access the 2nd site in different browser or in incognito mode everything works properly.

1
  • That's an interesting issue to learn about, thanks for posting about it! Commented Jun 14, 2018 at 6:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.