这里假设域名指万网/阿里云上申请,并从阿里云上申请免费证书
1、登录网址https://common-buy.aliyun.com/?spm=5176.100239.blogcont65199.23.WSIxVE&commodityCode=cas#/buy
2、选择Symantec和增强型OV SSL证书,这时通常会出现“免费型DV SSL”证书的选项
3、选择免费型DV SSL证书
4、购买(不花钱)
5、购买成功后会出现跳转到证书控制台的按钮。
二、设置并生成证书
1、进入证书控制台后,在列表中找到刚刚购买的证书,点击“补全”
2、输入二级域名名称(免费证书只支持单个二级域名)
3、输入申请人资料,选择系统自动生成csr文件
4、提交企业资料(如果域名是在阿里云申请的,并且已经备案,自动跳过)
5、提交审核
6、等待审核通过后下载证书
三、配置证书
1、下载证书并上传到nginx所在服务器
2、打开xxx.crt证书,把gd_bundle-g2-g1.crt证书的内容复制到后面,保存
3、修改nginx子域名配置文件
server { listen 443; server_name 域名; client_max_body_size 100m; client_body_buffer_size 10240k; ssl on; ssl_certificate ssl证书crt文件地址; ssl_certificate_key ssl证书密匙文件地址; root "项目根目录"; autoindex on; index index.html index.htm index.php; location / { index index.html index.htm index.php; try_files $uri $uri/ /index.php; rewrite ^/(?!index\.php|robots\.txt|html|image|js|css|third|lib|fonts|upload)(.*)$ /index.php/$1 last; } access_log /www/nginx/logs/access.log; error_log /www/nginx/logs/error.log; location ~ ^(.+\.php)(.*)$ { root 项目根目录; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_pass unix:/var/run/php-fpm.sock; include fastcgi_params; fastcgi_buffer_size 51200k; fastcgi_buffers 6 51200k; fastcgi_busy_buffers_size 51200k; fastcgi_temp_file_write_size 51200k; fastcgi_intercept_errors on; } }
参考:https://www.javatang.com/archives/2016/10/17/11151433.html