Nginx配置http跳转https访问

nginx的rewrite方法
可以把所有的HTTP请求通过rewrite重写到HTTPS上
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   rewrite ^(.*)$  https://XXXXXX.com permanent;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   return 301 https://$server_name$request_uri;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   rewrite ^(.*)$  https://$host$1 permanent;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
nginx的497状态码
497 – normal request was sent to HTTPS  
当前站点只允许HTTPS访问,当使用HTTP访问nginx会报出497错误码
可以使用error_page 把497状态码链接重新定向到HTTPS域名上
 
server{
   listen 80;
   server_name XXXXX.com;  //你的域名
   error_page 497  https://$host$uri?$args;
   location ~ / {
   index index.html index.php index.htm;
}
}
 
meta刷新作用将http跳转到HTTPS
index.html
<html>
 <meta http-equiv=”refresh” content=”0;url=https://XXXX.com/”>
 </html>
 
nginx配置
 
 
   listen 80;
   server_name XXXXX.com;  //你的域名
   location ~ / {
   root /var/www/test/;
   index index.html index.php index.htm;
   }
   error_page 404 https://xxxx.com

 



上一篇: PHP UNICODE编码(\u) 和UTF-8 之间转换
下一篇: php怎么输出数组
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: nginx
相关日志:
评论: 0 | 引用: 0 | 查看次数: 66
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭

 广告位

↑返回顶部↑