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安装(略 ...
随机推荐
- DB Create and Insert
<?php $servername = "localhost"; $username = "username"; $password = "pa ...
- 6、网页制作Dreamweaver(HTML结构--dom操作)
一.基本语法:数据类型(字符串,小数,整数,布尔,时间) var, var s = "3.14"; var n = parseFloat(s); ; s += 5; var d = ...
- Cryptography加密和解密
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Se ...
- 重学STM32---(八)----SDIO
1. SDIO(SD/SDIO MMC卡主机模块)在AHB外设总线和多媒体卡(MMC).SD存储卡.SDIO卡和CE-ATA设备间提供了操作接口.(SDIO没有SPI兼容的通信模式 ) 1.1.什么是 ...
- 利用range() 控制循环
s = ['a','b','c','d','e'] for i in range(len(s)):... if i < len(s)-1:... print s[i] a ...
- JS初学之-循环生成坐标
<!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...
- 工作中遇到的问题--eclipse没有方法提示
一.eclipse自身配置问题步骤:1. 打开Eclipse ,然后“window”→“Preferences”2. 选择“java”,展开,“Editor”,选择“Content Assist”.3 ...
- Codeforces378 D Kostya the Sculptor(贪心)(逻辑)
Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- 课堂所讲整理:super和转型(修改版)
创建父类: package org.hanqi.pn0120; public class Father { private String name; private int age; public S ...
- UVALive-4670 Dominating Patterns(AC自动机)
题目大意:找出出现次数最多的模式串. 题目分析:AC自动机裸题. 代码如下: # include<iostream> # include<cstdio> # include&l ...