1.推荐配置
server {
listen 80;
server_name example1.com example2.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name example1.com example2.com;
...
}
2.为什么使用$host
- $host is used instead of $server_name to properly match between server block the corresponding domains
3.照搬链接
- https://zaiste.net/rewrite_http_to_https_in_nginx/
- https://bjornjohansen.no/redirect-to-https-with-nginx
- https://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom