nginx 强制http跳转到https的配置文件

1、上篇文章说了怎么在nginx开启ssl模块,开启后怎么让http强制跳转到https

原文章:http://www.cnblogs.com/renew/p/7910621.html

2、配置文件

#先监听80端口,为http请求,然后强制转发到https监听的443端口上面
server {
  listen       80;
  root         path;
  server_name  www.exp.com;
  rewrite ^(.*) https://$server_name$1 permanent;
}

#监听443端口,https请求
server {
  listen                 443 ssl;
  root                   path;
  server_name            www.exp.com;
  ssl_certificate        证书文件.crt;
  ssl_certificate_key    证书文件.key;
  
  #此段代码为rapidPHP单一入库配置,不是rapidPHP框架请忽略
  #location / {
  #  if (!-e $request_filename){
  #    rewrite ^(.*)$ /index.php?__ROUTE__=$1 last;
  #  }
  #}

  location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}

配置完成重启nginx即可

posted @ 2017-11-28 16:22  Renew全栈开发工程师  阅读(2879)  评论(0编辑  收藏  举报