In my VPS I have hosted two different domains for eg:
https://example1.in
and https://example2.com
in single VPS, here I’ve enabled the SSL certificate for the both.
If I trying to access my domain https://example2.com
it works fine but if I remove the s
from https
for eg: http://example2.com
, it will redirect to the https://example1.in
.
sites-available and enable for example2.com
<code>server {
listen 8576;
server_name example2.com;
# redirects both www and non-www to https
return 301 https://example2.com$request_uri;
}
</code>
<code>server {
listen 8576;
server_name example2.com;
# redirects both www and non-www to https
return 301 https://example2.com$request_uri;
}
</code>
server {
listen 8576;
server_name example2.com;
# redirects both www and non-www to https
return 301 https://example2.com$request_uri;
}
for example1.in
<code>server {
listen 80;
server_name example1.in;
# redirects both www and non-www to https
return 301 https://example1.in$request_uri;
}
</code>
<code>server {
listen 80;
server_name example1.in;
# redirects both www and non-www to https
return 301 https://example1.in$request_uri;
}
</code>
server {
listen 80;
server_name example1.in;
# redirects both www and non-www to https
return 301 https://example1.in$request_uri;
}
4
Just replace this:
<code>return 301 https://example1.in$request_uri;
</code>
<code>return 301 https://example1.in$request_uri;
</code>
return 301 https://example1.in$request_uri;
with this:
<code>return 301 https://$host$request_uri;
</code>
<code>return 301 https://$host$request_uri;
</code>
return 301 https://$host$request_uri;