nginx 配置 https

2020-03-19  本文已影响0人  剑风i
1.阿里云购买免费证书
2.编辑/etc/nginx/conf.d/conf/nginx.conf 配置文件:
server{
    listen       80;
    # 服务器端口使用443,开启ssl
    listen       443 ssl;
    # 域名,多个以空格分开
    server_name www.baidu.com;
    index index.php index.html index.htm;
    root  项目目录;

    ssl_certificate "/etc/nginx/cert/xxx.pem";
    ssl_certificate_key "/etc/nginx/xxx.key";

    location ~ /check.html {
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }

    location ~ ^(.*)\/\.svn\/ {
            deny all;
    }

    location ~ /\.(svn|git) {
        deny all;
    }
}
3.nginx配置http自动跳转https

把HTTP请求通过rewrite重写到HTTPS上

上一篇 下一篇

猜你喜欢

热点阅读