nginx 全站 http 跳转 https
server {
listen 80;
server_name www.xxx.com;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name www.xxx.com;
ssl_certificate /etc/nginx/ssl/www.xxx.com.pem;
ssl_certificate_key /etc/nginx/ssl/www.xxx.com.key;
ssl on;
root /home/www/xxx;
location / {
# ...
}
}
打赏: 微信
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
我一般习惯这样写:
server { listen 80; listen 443 ssl http2; server_name domain.com; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/project; if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } . . . }你这个看起来更简洁呢!