Question
Nginx redirect error when http to https including www
Hello,
i need all http to redirect to https. also non-www to be redirect to www version as well. so i tried with this single redirect rule
return 301 https://www.$server_name$request_uri;
And this is my server block.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mysite.com www.mysite.com;
return 301 https://www.$server_name$request_uri;
}
server {
listen 80;
listen [::]:80;
server_name forum.mysite.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name mysite.com www.mysite.com forum.mysite.com;
all domain work perfectly except when i type https://mysite.com
it redirect to address https://www.mysite.com/wp-signup.php?new=mysite.com
note, this happen only when i typed with https.
anyone has any idea why this is happening? i found out this today when i went to my both domains to google search console. when i typed https://mysite.com i saw this issue.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×