nginx的https配置

2020-05-28  本文已影响0人  炒面Z
server {
    listen 443 ssl;
    listen 80;
    charset utf-8;
    server_name www.domain.com;
    root /usr/share/nginx/mobile;
    index   index.html;

    #为一个server开启ssl支持  
    #ssl    on;  
    
    #指定PEM格式的证书文件   
    ssl_certificate      /usr/share/nginx/sairobo-ssl/3981790_www.domain.com.pem;   
    #指定PEM格式的私钥文件  
    ssl_certificate_key  /usr/share/nginx/sairobo-ssl/3981790_www.domain.com.key;

    #让http请求重定向到https请求
    if ($server_port = 80){ 
    return 301 https://$host$request_uri;}
    if ($scheme = http){
    return 301 https://$host$request_uri;}
    error_page 497  https://$host$uri?$args;

    # 忽略favicon.ico文件的404错误日志
    location ~ ^/favicon\.ico$ {
        root /usr/share/nginx/mobile;
    }

    # history模式必须要加
    location / { try_files $uri $uri/ /index.html; }

}
上一篇 下一篇

猜你喜欢

热点阅读