I am hosting multiple domains on a server with nginx server blocks. For some reason when other domains are requested with https it always loads one particular website.
- domain1.com /var/www/domain1.com
- domain2.com /var/www/domain2.com ...
When I type http://domain1.com this loads correctly but when I type https://domain1.com it serves what's under /var/domain2.com
Below is my nginx config for domain2 server block which has ssl. I am guessing the listen 443 ssl default_server; on the 3rd server block is the culprit but not sure how to proceed. I tried removing the default_server from there but that breaks the site.
How do I configure the nginx config so that other domains are not serving the wrong website when requested with https. I appreciate any help.
# Default server configuration # server { listen 80; listen [::]:80; server_name domain2.com www.domain2.com; return 301 https://www.domain2.com$request_uri; } server { listen 443; listen [::]:443; server_name domain2.com; return 301 https://www.domain2.com$request_uri; } server { # SSL configuration listen 443 ssl default_server; listen [::]:443 ssl default_server; server_name www.domain2.com; include snippets/ssl-domain2.com.conf; include snippets/ssl-params.conf; # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/domain2.com; # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.php?$args; } ...