Nginx 配置 HTTP 跳转 HTTPS


#Nginx


以静态博客为例:

server {
    listen 443 ssl;
    server_name www.example.com;
    root /path/to/blog/;

    ssl on;
    ssl_certificate      /path/to/ssl_cer;
    ssl_certificate_key  /path/to/ssl_key;

    location ~.*\.(ico|css|js|gif|jpe?g|png)$ {
        expires 2h;
    }
    location / {
        index index.html index.htm;
        error_page 404 /404.html;
        expires  2h;
    }
}

server {
    listen 80;
    listen   [::]:80 default ipv6only=on; ## listen for ipv6
    server_name www.example.com;
    return 301 https://$server_name$request_uri;
}

( 本文完 )