LNMP強制https訪問

LNMP設置強制https訪問能夠添加一個rewrite,也能夠經過一條301跳轉實現,推薦第二種方式。在實際設置的時候須要在虛擬主機的conf文件裏多加一個server段,443監聽在上面,80端口在下面。若是順序反了則會出現跳轉到了nginx歡迎界面的狀況。通常虛擬主機配置文件位於:/usr/local/nginx/conf/vhost/域名.conf,在配置文件最後面加上以下代碼,自行修改相應配置:php

普通的根域名301跳轉到www域名css

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

 

http強制跳轉到https並開啓http2

server
{
  listen 443 ssl;
  server_name sdk.open.test.com;
  index index.html index.htm index.php;
  root /data/www/web/;
  charset utf-8;
 
  location ~.*\.(swf|xml|mp3|png|jpg|gif|data)$ {
  expires max;
  }
 
  location ~.*\.(css|js|mx)$ {
  expires 96h;
  }
 
  location ~ /.svn/ {
  deny all;
  }
 
  location ~ .*\.php$
  { 
    include fastcgi.conf;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    expires off;
  }
 
  ssl on;
  ssl_certificate /usr/local/nginx/ssl/ea93balk25xh3f9.crt;
  ssl_certificate_key /usr/local/nginx/ssl/9yrt62bv1z4s35la.key;
 
  access_log /data/logs/sdk.open.test.com.access.log access;
  error_log   /data/logs/sdk.open.test.com.error.log warn;
}
server
{
  listen 80;   server_name sdk.open.test.com;   return 301 https://$server_name$request_uri; //rewrite ^/(.*) https://ssl.lanbing.org/$1 permanent; #關鍵代碼仔細比較二者的跳轉的區別 }
相關文章
相關標籤/搜索