一定要把nginx的两个证书放到/usr/local/nginx/conf下
如果安装了宝塔,直接打开对应网站的配置文件,之后将下方代码改成属于自己的粘贴进去即可
server{
listen 80;
server_name www.manongw.com;
#告诉浏览器有效期内只准用 https 访问
add_header Strict-Transport-Security "max-age=31536000";
#永久重定向到 https 站点
return 301 https://$server_name$request_uri;
}
server{
listen 443;
#listen [::]:80 default_server ipv6only=on;
server_name www.manongw.com;
ssl on;
ssl_certificate /usr/local/nginx/conf/fullchain.pem;
ssl_certificate_key /usr/local/nginx/conf/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/www.manongw.com;
#error_page 404 /404.html;
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-72.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /usr/local/nginx/conf/www.manongw.com.conf;
#REWRITE-END
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;
error_log /home/wwwlogs/access.error.log;
}
粘贴之后保存,打开浏览器摁F12,输入内页网址http://www.manongw.com/article/311.html ,敲完回车之后如果跳转,则会出现2个页面,如下图
第一个则为http的界面,第二个则为https的代码,分别打开2个界面,显示如下图所示:
上图中的Status Code中出现301则为重定向成功!