前提: 阿里云服务器,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