服务器 添加 SSL 操作记录

前提: 阿里云服务器,nginx  php7  tp5.1

同一套程序,2个域名,其实一个域名需要添加https【因为腾讯的原因】

简单的记录下配置文件,暂定域名为 abc.com;

1、阿里云下载ssl证书

2、把配置文件修改成  域名前缀  【abc.pem ,abc.key】

3、上传2个文件到  /usr/local/nginx/conf/cert 【需要创建 cert文件夹】

4、修改配置文件,  /usr/local/nginx/conf/vhost/abc.conf 【全部的配置,引入了thinkphp的伪静态】

server
    {
        listen 80;
        #listen [::]:80;
        server_name abc.com ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/abc.com/public;
        
        rewrite ^(.*)$ https://$host$1 permanent;   #将所有http请求通过rewrite重定向到https。    
    
        include rewrite/thinkphp.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log off;
    }

  
server {
	listen 443 ssl;
	server_name abc.com ;
	root /home/wwwroot/abc.com/public;
	index index.php index.html index.htm;
	ssl_certificate /usr/local/nginx/conf/cert/abc.pem;
	ssl_certificate_key /usr/local/nginx/conf/cert/abc.key;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	ssl_prefer_server_ciphers on;
	include enable-php.conf;
    index index.html index.htm index.php default.html default.htm default.php;
   
    include rewrite/thinkphp.conf;

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }

    location ~ /.well-known {
        allow all;
    }

    location ~ /\.
    {
        deny all;
    }

    access_log off;
      
}

5、重启nginx服务器即可实现 ;

注:

1、如果不希望http主动跳转到https,  删除    rewrite ^(.*)$ https://$host$1 permanent; 这句即可

2、确保阿里云开放443端口

 

 

 

阿里帮助文档:

https://help.aliyun.com/document_detail/98728.html?spm=5176.2020520163.0.0.5e7956a7d69wn0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值