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 / {
        # ...
    }
}
已有 2 条评论
  1. Secret

    我一般习惯这样写:

    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; } . . . }
    Secret April 9th, 2019 at 04:48 pm回复
    1. LukaChen

      你这个看起来更简洁呢!

      LukaChen April 9th, 2019 at 05:00 pm回复
发表新评论