1.到腾讯云ssl页面:申请免费ssl证书
https://console.cloud.tencent.com/ssl
选择免费证书
默认左边直接点确定
填写域名信息
填写之后点下一步,选择第一个自动DNS。完成之后会出现待验证,等待一段时间,后台自动验证之后就可以先下载
会有黄字提醒下面这个,不用管
您有1个SSL证书未完成身份验证,请尽快处理
一步一步走,申请成功之后,等一段时间(我的没超过一小时)。可以下载
2.把下载下来的证书上传到服务器
下载下来的文件有下面几个,服务器配置用的是哪个就选择哪个使用
选择nginx里的两个文件:
代码语言:javascript复制.cn_bundle.crt
.cn.key
在服务器的项目代码目录,创建crt文件夹,把两个文件上传到crt文件夹中,我用的是laravel项目,所以实在这个目录下
3.配置nginx
在nginx配置下修改,你的可能是别的路径
代码语言:javascript复制sudo vim /etc/nginx/conf.d/default.conf
代码语言:javascript复制server {
listen 80;
server_name 域名;
set $root_path ‘public地址‘;
root $root_path;
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)/(. )$ {
root $root_path;
}
location ~ /.ht {
deny all;
}
}
server {
listen 443 ssl http2;
server_name 域名 ;
root public地址;
index index.php index.html index.htm;
ssl off; # 开启ssl证书访问
ssl_certificate .cn_bundle.crt路径;
ssl_certificate_key .cn.key路径;
ssl_session_timeout 10m; # session有效期10分钟
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 协议版本 按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
ssl_prefer_server_ciphers on;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
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;
}
}
nginx重启
代码语言:javascript复制sudo systemctl restart nginx
如果报如下错误
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
查看错误信息
代码语言:javascript复制systemctl status nginx.service
代码语言:javascript复制如果报下面的错,证书路径错误修改路径
nginx.service - The nginx HTTP and reverse proxy server
重启出现下边成功
代码语言:javascript复制Redirecting to /bin/systemctl restart nginx.service