Nginx配置站点https

Posted feanmy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx配置站点https相关的知识,希望对你有一定的参考价值。

step 1: 检查nginx的编译参数

使用nginx -V可以查看,如果编译参数中包含http_ssl_module,可以继续下一步操作,如果没有,则需要从新编译。

技术分享图片

step 2: 申请证书

目前,阿里云等云平台可以申请一定时间的免费证书,这里大家可以自行找下,不再多说

step 3: 配置nginx.conf

server {
    listen 443;
    server_name hae.top;
    ssl on;
    ssl_certificate      /usr/local/nginx/key/214665654330627.pem;
    ssl_certificate_key  /usr/local/nginx/key/214665654330627.key;
    ssl_session_timeout  5m;
    ssl_protocols  TLSv1 TLSv1.1  TLSv1.2;
    ssl_ciphers     ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_prefer_server_ciphers   on;


    index index.html index.htm index.php;
    root  /home/wwwroot/default/public;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ [^/]\\.php(/|$) {
        # comment try_files $uri =404; to enable pathinfo
        try_files $uri =404;
        fastcgi_pass unix:/tmp/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_param PHP_ADMIN_VALUE "open_basedir = /home/wwwroot: /temp/:/proc";
    }
}

接着使用https访问站点即可

以上是关于Nginx配置站点https的主要内容,如果未能解决你的问题,请参考以下文章

Nginx配置ssl证书(https),给自己的站点上绿锁

Nginx配置ssl证书(https),给自己的站点上绿锁

Nginx配置ssl证书(https),给自己的站点上绿锁

配置 nginx 以从单个服务器提供 HTTP 和 HTTPS 站点的麻烦

nginx 站点80跳443配置

基于Nginx配置https证书