nginx 强制http跳转到https

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

原文章:http://www.jianshu.com/p/bcd3e946c183

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即可

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容