nginx 配置https协议

如何在nginx 服务器上配置https协议

一、腾讯云购买的SSL证书

步骤1、

购买SSL证书 ,可购买免费版的,当状态为已颁发之后 下载证书

步骤2、

在站点服务器上开启443端口(这点很重要)

步骤3、

配置nginx.conf文件

server {
     #SSL 访问端口号为 443
     listen 443 ssl;
     #填写绑定证书的域名
     server_name   www.xxx.com;
     #证书文件名称
     ssl_certificate /etc/nginx/1_www.antheamlhotel.com_bundle.crt;
     #私钥文件名称
     ssl_certificate_key /etc/nginx/2_www.antheamlhotel.com.key;
     ssl_session_timeout 5m;
     #请按照以下协议配置
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
     #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
     ssl_prefer_server_ciphers on;

    root             /data/meilan;
    index            index.php index.html index.htm;
   try_files        $uri $uri/ @rewrite;

   location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ .php$ {
        fastcgi_pass                  127.0.0.1:9000;
        fastcgi_index                 index.php;
        fastcgi_split_path_info       ^(.+.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include                       fastcgi_params;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
    }

    location ~ /.ht {
         deny all;
    }

    #禁止访问的文件或目录
    location ~ ^/(.user.ini|.htaccess|.git|.svn|.project|LICENSE|README.md)
    {
        return 404;
    }

}

server{
listen 80;
server_name www.xxx.com;
#把http的域名请求转成https
return 301 https://$host$request_uri;
}

结束

原文地址:https://www.cnblogs.com/sz-xioabai/p/13280921.html