http301到https,以实现求更简洁方法

我用阿里云的免费htts服务,实现了https的访问,为了更好的SEO效果,做了 http所有页面301到http页面,但是我这种方式并不简洁。贴一下我的代码。后续继续学习找一个更简洁的方法。

server{

  listen        443 ssl;
  server_name   www.mishinan.cn;
  root          /home/www/www.mishinan.cn;
  index         index.html index.php;
  ssl_certificate   /etc/nginx/ssl/mishinan/214543142520385.pem;
  ssl_certificate_key  /etc/nginx/ssl/mishinan/214543142520385.key;
  ssl_session_timeout 5m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
  ssl_prefer_server_ciphers on;
  location / {
    try_files $uri $uri/ /index.php?$query_string;
    if ( !-e $request_filename ) {
     # proxy_pass      http://index;
    }
  }


  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi.conf;
  }
}


server {
  listen  80;
  server_name   www.mishinan.cn;
  return  301 https://www.mishinan.cn$request_uri;
  root          /home/www/www.mishinan.cn;
  index         index.html index.php;
  ssl_session_timeout 5m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
  ssl_prefer_server_ciphers on;
  location / {
    try_files $uri $uri/ /index.php?$query_string;
    if ( !-e $request_filename ) {
     # proxy_pass      http://index;
    }
  }
  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi.conf;
  }
}

猜你喜欢

转载自blog.csdn.net/mishinan/article/details/80676405