第一步:去云服务器平台下载ssl证书,下载下来解压后里面会有俩文件
第二步将这个文件放在一个文件夹里面比如叫cert.将改文件上传到服务器/usr/local/nginx/conf目录里
第三步:打开要加https的域名配置文件,将原来里面的整个server里面内容复制一份,放在原来那个server下边,如下.
server
{
listen 80;
#listen [::]:80 default_server ipv6only=on;
server_name bus.tjgbank.cn;
index index.html index.htm index.php book.php;
root /home/wwwroot/default/bus/public;
#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 / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
# location /
#{
# try_files $uri $uri/ /index.php?$query_string;
# }
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
server
{
listen 443;
#listen [::]:80 default_server ipv6only=on;
server_name bus.tjgbank.cn;
index index.html index.htm index.php book.php;
root /home/wwwroot/default/bus/public;
#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 / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
ssl on;
ssl_certificate cert/a.pem;
ssl_certificate_key cert/a.key;
ssl_session_timeout 5m;
ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!aNULL:!eNULL;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# location /
#{
# try_files $uri $uri/ /index.php?$query_string;
# }
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
下边那个server里面ssl开头的是使https生效的关键部分。
第四步:保存退出然后service nginx restart重新就ok了!是不是so easy