军哥LNMP强制https访问设置

LNMP设置强制https访问可以添加一个rewrite,也可以通过一条301跳转实现,军哥推荐第二种方式。在实际设置的时候需要在虚拟主机的conf文件里多加一个server段,443监听在上面,80端口在下面。如果顺序反了则会出现跳转到了nginx欢迎界面的情况。一般虚拟主机配置文件位于:/usr/local/nginx/conf/vhost/域名.conf,在配置文件最后面加上如下代码,自行修改相应配置:

普通的根域名301跳转到www域名

server {
listen 80;
server_name notehubs.com;
return 301 http://www.notehubs.com$request_uri;
}

http强制跳转到https并开启http2

server
{
listen 443 ssl http2;
server_name  notehubs.com;
ssl_certificate /root/notehubs.crt;
ssl_certificate_key /root/notehubs.key;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/notehubs.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/www/notehubs.com.log access;
}
server {
listen 80;
server_name notehubs.com;
return 301 https://notehubs.com$request_uri;
}

本文来自,经转载后发布,本文观点不代表NoteHubs立场,仅供技术交流使用,转载请联系原作者。如果发现本站有涉嫌损害您利益的内容,欢迎发送邮件至 jackyeow@notehubs.com 举报,一经查实,本站将立刻删除涉嫌侵权的内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 2019年10月11日 10:47
下一篇 2019年12月18日 19:58

相关推荐