- A+
所属分类:工具资源
LNMP设置强制https访问可以添加一个rewrite,也可以通过一条301跳转实现,军哥推荐第二种方式。在实际设置的时候需要在虚拟主机的conf文件里多加一个server段,443监听在上面,80端口在下面。如果顺序反了则会出现跳转到了nginx欢迎界面的情况。一般虚拟主机配置文件位于:/usr/local/nginx/conf/vhost/域名.conf,在配置文件最后面加上如下代码,自行修改相应配置:
普通的根域名301跳转到www域名
关键几行www.cmsky.com虚拟主机server配置
server {
listen 80;
server_name cmsky.com;
return 301 https://past.cmsky.org$request_uri;
}
http强制跳转到https并开启http2
server
{
listen 443 ssl http2;
server_name cmsky.com;
ssl_certificate /root/cmsky.crt;
ssl_certificate_key /root/cmsky.key;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/cmsky.com;
include other.conf;
#error_page 404 /404.html;
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/cmsky.com.log access;
}
server {
listen 80;
server_name cmsky.com;
return 301 https://past.cmsky.org$request_uri;
}
我的微信公众号
我的微信公众号扫一扫

2016年6月20日 上午11:29 沙发
Warning: Use of undefined constant auto - assumed 'auto' (this will throw an Error in a future version of PHP) in /www/wwwroot/past.cmsky.org/wp-content/themes/begin5.2/inc/inc.php on line 911
感谢!试了几十种方法,用你的方法终于对了
2016年11月10日 上午10:47 板凳
Warning: Use of undefined constant auto - assumed 'auto' (this will throw an Error in a future version of PHP) in /www/wwwroot/past.cmsky.org/wp-content/themes/begin5.2/inc/inc.php on line 911
还可以在服务器侧使用Rewrite(如果已安装)
[code]rewrite ^(.*)$ https://$host$1 permanent;[/code]
这样在客户端观察就没有30x的重定向的过程