首页技术博客 服务器运维 正文

nginx环境下使用rewrite伪静态使http跳转到https的方法(301重定向)

2018-03-12 2595 0条评论

首先,你得先把https配置好 Nginx下配置网站SSL实现https访问(虚拟主机)


然后在nginx文件夹下找到对应的虚拟主机配置文件,路径为:www/haozilinux/nginx/conf/vhost


然后对该虚拟主机配置文件做如下修改:

server {


listen 443;


root /www/web/fuyulife/public_html;

server_name www.fuwenhao.com www.fuwenhao.com;

index  index.html index.php index.htm;

error_page  400 /errpage/400.html;

error_page  403 /errpage/403.html;

error_page  404 /errpage/404.html;

error_page  503 /errpage/503.html;

ssl on;

ssl_certificate_key  /www/haozilinux/nginx/conf/fuwenhao.key;

ssl_certificate  /www/haozilinux/nginx/conf/fuwenhao.crt;


location ~ \.php$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

include fcgi.conf;

}

location ~ /\.ht {

deny  all;

}

include /www/haozilinux/wdcp/rewrite/dzx32_nginx.conf;

}

  server {

listen      80;

server_name    www.fuwenhao.com;

return      301 https://$server_name$request_uri;

}


 


蓝色部分为rewrite规则,原理是监听443端口使用https,监听80端口使用301重定向到https.


 




文章版权及转载声明

本文作者:符文浩 网址:http://blog.fuwenhao.com/post/59.html 发布于 2018-03-12
文章转载或复制请以超链接形式并注明出处。

发表评论

快捷回复:

评论列表 (暂无评论,2595人围观)参与讨论

还没有评论,来说两句吧...

取消
微信二维码
微信二维码
支付宝二维码