网站ssl https设置

设置成https首先需要证书,我的证书是在阿里云申请的,具体步骤到阿里云控制台申请ca证书,申请完后得到两个文件,分别以.key和.pem结尾的文件。
申请完后把两个文件放在nginx安装目录(usr/local/nginx)的cert目录下,没有cert要手动创建,然后到nginx的配置文件下添加配置:
server {
listen 80;
server_name www.mayijiangren.com;
rewrite ^(.* ) h t t p s : / / ) https:// host$1 permanent;#这是把http请求跳转到https
}

server {
listen 443;
server_name www.mayijiangren.com;
ssl on;
root html;
index index.html index.htm;
ssl_certificate /usr/local/nginx/cert/1210840.pem; #这是从阿里云申请下的
ssl_certificate_key /usr/local/nginx/cert/1210840.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;

       location / {
        #root html;
        index index.html index.htm;
        proxy_pass http://ant-portal; #这里要根据实际情况进行跳转
        }

  }

添加完以后重启nginx,有可能重启不了出现错误,原因可能是安装nginx的时候没有加载ssl的模块儿,这就需要先把nginx重新编译下了,具体步骤:
1.找到nginx的解压文件夹,执行 ./configure --with-http_ssl_module
2.make 千万别make install,否则就覆盖安装了

3.make完之后在objs目录下就多了个nginx,这个就是新版本的程序了

cp objs/nginx /usr/local/nginx/sbin/nginx

测试新的nginx程序是否正确

/usr/local/nginx/sbin/nginx -t

nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful
然后重启nginx就可以了。

猜你喜欢

转载自blog.csdn.net/qq_21566775/article/details/85266905