更新时间:2016-03-03 16:48:44浏览次数:840+次
LNMP设置强制https访问可以添加一个rewrite,也可以通过一条301跳转实现,军哥推荐第二种方式。在实际设置的时候需要在虚拟主机的conf文件里多加一个server段,443监听在上面,80端口在下面。如果顺序反了则会出现跳转到了nginx欢迎界面的情况。一般虚拟主机配置文件位于:/usr/local/nginx/conf/vhost/域名.conf,在配置文件最后面加上如下代码,自行修改相应配置:
关键几行www.cmsky.com虚拟主机server配置 server?{ listen?80; server_name?cmsky.com; return?301?http://www.cmsky.com$request_uri; }
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://cmsky.com$request_uri; }