nginx http跳转到https
server {
listen 80;
server_name www.888.com;
location / {
#index.html放在虚拟主机监听的根目录下
root /usr/local/nginx/html/http.888.com/;
rewrite ^/(.*) https://www.888.com/$1 last;
}
#将404的页面重定向到https的首页
error_page 404 https://www.888.com/;
}
chown -R www:www /usr/local/nginx/html /usr/local/nginx/html/http.88888.com/index.html
<html>
<meta http-equiv="refresh" content="0;url=https://www.88888.com/">
</html>
需求简介
基于nginx搭建了一个https访问的虚拟主机,监听的域名是test.com,但是很多用户不清楚https和http的区别,会很容易敲成http://test.com,这时会报出404错误,所以我需要做基于test.com域名的http向https的强制跳转
我总结了三种方式,跟大家共享一下
nginx的rewrite方法
思路
配置
- server {
- listen 192.168.1.111:80;
- server_name test.com;
- rewrite ^(.*)$ https://$host$1 permanent;
- }
搭建此虚拟主机完成后,就可以将http://test.com的请求全部重写到https://test.com上了
nginx的497状态码
error code 497
- 497 - normal request was sent to HTTPS
解释:当此虚拟站点只允许https访问时,当用http访问时nginx会报出497错误码
思路
配置
- server {
- listen 192.168.1.11:443; #ssl端口
- listen 192.168.1.11:80; #用户习惯用http访问,加上80,后面通过497状态码让它自动跳到443端口
- server_name test.com;
- #为一个server{......}开启ssl支持
- ssl on;
- #指定PEM格式的证书文件
- ssl_certificate /etc/nginx/test.pem;
- #指定PEM格式的私钥文件
- ssl_certificate_key /etc/nginx/test.key;
- #让http请求重定向到https请求
- error_page 497 https://$host$uri?$args;
- }
index.html刷新网页
思路

index.html
- <html>
- <meta http-equiv="refresh" content="0;url=https://test.com/">
- </html>
nginx虚拟主机配置
- server {
- listen 192.168.1.11:80;
- server_name test.com;
- location / {
- #index.html放在虚拟主机监听的根目录下
- root /srv/www/http.test.com/;
- }
- #将404的页面重定向到https的首页
- error_page 404 https://test.com/;
- }
后记
nginx http跳转到https的更多相关文章
- nginx从http跳转到https
场景 项目前期使用http,后期为了安全方面的考虑,启用了https. 项目架构:前端使用nginx作为多个tomcat实例的反向代理和负载均衡. 实际上只需要在nginx上启用https即可,使客户 ...
- Nginx环境中如何将HTTP跳转至HTTPS设置
如果我们VPS服务器的WEB环境采用的是NGINX架构,那如果我们将安装SSL证书的网站希望强制跳转至HTTPS网站URL的时候那需要如何设置呢?这里个人建议是这样的,我们必须要强制一个地址,这样网站 ...
- Nginx配置http强制跳转到https
目的:访问http://sdk.open.test.com/时强制自动跳转到https://sdk.open.test.com/ 修改nginx站点配置文件sdk.open.test.com.conf ...
- CentOS 7 配置nginx并默认强制使用https对http进行跳转
1.安装nginx yum install nginx 2.启动nginx服务 service nginx start 3.开启防火墙80端口,云服务器和本地虚拟服务器各有不同,不再赘述. 4.访问你 ...
- nginx强制使用https访问(http跳转到https)
Nginx 的 Location 从零开始配置 - 市民 - SegmentFault 思否https://segmentfault.com/a/1190000009651161 nginx配置loc ...
- Nginx的https配置记录以及http强制跳转到https的方法梳理
一.Nginx安装(略)安装的时候需要注意加上 --with-http_ssl_module,因为http_ssl_module不属于Nginx的基本模块.Nginx安装方法: 1 2 # ./con ...
- nginx配置http访问自动跳转到https
1.按照如下格式修改nginx.conf 配置文件,80端口会自动转给443端口,这样就强制使用SSL证书加密了.访问http的时候会自动跳转到https上面 server { listen ; se ...
- nginx证书制作以及配置https并设置访问http自动跳转https(反向代理转发jboss)
nginx证书制作以及配置https并设置访问http自动跳转https 默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖 ...
- (转)Nginx的https配置记录以及http强制跳转到https的方法梳理
Nginx的https配置记录以及http强制跳转到https的方法梳理 原文:http://www.cnblogs.com/kevingrace/p/6187072.html 一.Nginx安装(略 ...
随机推荐
- Washing Clothes_01背包
Description Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a ...
- DirectX游戏编程入门
刚开始学习D3D,安装完DirectX9后,在VS2008中新建Win32项目· ----------------------------------------------------------- ...
- HDU 4576
http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给一个1-n的环,m次操作,每次操作顺时针或逆时针走w步,求最后落在[l,r]区间的概率 dp[i] ...
- Think Python - Chapter 17 - Classes and methods
17.1 Object-oriented featuresPython is an object-oriented programming language, which means that it ...
- 发布b3log-solo后,访问http://localhost:8080/b3log-solo/提示错误为staticServePath Error。
发布b3log-solo后,访问http://localhost:8080/b3log-solo/提示错误为staticServePath Error. latke.props内容为: serverS ...
- 博客引索 - imsoft.cnblogs
Java C Delphi 日常工具 图片处理 视频处理 系统工具 知识经验 奇思妙想 网站推荐
- suse linux修改hostname
SUSELinux中修改hostname需要修改以下两个文件 $vi /etc/HOSTNAME $vi /etc/hosts 然后重启系统即可.
- Java-->简单的斗地主发牌流程
package com.dragon.java.hwddz; import java.util.ArrayList; import java.util.HashMap; import java.uti ...
- 利用powerdesigner反向数据库结构,生成ER图
参考月下狼~图腾~:<利用powerdesigner反向数据库结构,生成ER图> https://www.zybuluo.com/Jpz/note/123582 首先新建一个"P ...
- crontab 安装 和一些 简单的命令
crontab命 令常见于Unix和Linux的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供 之后读取和执行.通常,crontab ...