I know that there are other questions with similar topics, but I can't find a solution anywhere that solves my specific problem. The difference here is multiple domains with different sites.
I have Nginx set up with multiple domains: example1.com
and example2.com
. There's also the "default" host files that have the "Welcome to Nginx!" default web page.
I've tried a few different configurations including:
# 1
server {
server_name example2.com www.example2.com;
listen 80;
return 301 https://example2.com$request_uri;
}
server {
server_name example2.com www.example2.com;
listen 443 default_server;
ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example2.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
# 2
server {
server_name example2.com www.example2.com;
listen 80;
listen 443
return 301 https://example2.com$request_uri;
ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example2.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
1
results in:
- http://example2.com redirecting to https://example2.com showing the "Welcome" page
- http://example1.com redirecting to https://example2.com showing the "Welcome" page
- https://example1.com showing the actual content of example1.com
2
results in:
- http://example2.com with a redirect loop
- https://example2.com with a redirect loop
- http://example1.com redirecting to http://example2.com with a redirect loop
- https://example1.com showing the actual content of example1.com
I can't put the content for example2.com
in the default "Welcome" folder or it would affect example1.com
.
root
directive and will therefore pointhttps://example2.com
to thenginx
default page, and option (2) redirects to itself.