Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 599 Bytes

nginx-301-http-https.md

File metadata and controls

27 lines (21 loc) · 599 Bytes

Nginx利用301实现http自动跳转到https

{"Author":"yanwei", "LastUpdate":"2018-01-24"}

80端口访问时,直接返回301重定向到https链接即可。Nginx配置示例如下:

server {
    listen 443 ssl;
    server_name example.com;

    ssl on;
    ssl_certificate /etc/nginx/sslkey/your-ssl.pem;
    ssl_certificate_key /etc/nginx/sslkey/your-ssl.key;
    ...
}

server {
    listen 80;
    server_name www.example.com example.com;
    return 301 https://example.com$request_uri;
}