要求:已签发https证书,并下载了nginx版本的证书(可申请免费的阿里云https证书)
步骤一:
将证书上传至nginx的某个文件夹内(自定义)
步骤二:
编辑nginx的配置文件nginx.conf,为每个域名添加单独的server块
server {
listen 443 ssl;
server_name test.test.com;
# 证书路径
ssl_certificate /www/server/panel/test.test.com.pem;
ssl_certificate_key /www/server/panel/test.test.com.key;
# 根目录设置(关键!)
root /www/wwwroot/test.test.com;
index index.html index.php;
# 其他必要配置
include enable-php.conf;
access_log /www/wwwlogs/test.test.com.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
步骤三:
配置http自动跳转https
# HTTP 跳转 HTTPS 通用配置
server {
listen 80;
server_name test.test.com test2.test.com test3.test.com test4.test.com;//修改成自己的域名
return 301 https://$host$request_uri;
}
步骤四:
输入网址进行测试,测试前清理浏览器缓存,通用浏览器清缓存快捷键:shift+ctrl+delete