How to do it.....
For example, nginx.conf file for your website
server {Note: Using $host instead of $server_name to according to block your server.
listen 80;
listen [::]:80;
if ($host = www.huuphan.com) {
return 301 https://$host$request_uri;
}
if ($host = huuphan.com) {
return 301 https://$host$request_uri;
}
server_name www.huuphan.com huuphan.com;
return 444;
#return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.huuphan.com huuphan.com;
access_log off;
error_log /path/to/logs/error.log;
root /path/to/webroot;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
}
}
Thanks for reading Nginx redirect all http to https My blog Effortless Zimbra Mail Management: Unleashing the Power of Linux Commands, How-To, and Bash Scripts I hope this is useful.