平常最多的需求是将baidu.com指向全域名www.badu.com,但是往往需求是各种各样,这两天就遇到一个反向需求。将baidu.com直接访问网站,而不做跳转。

最近两天在给域名证书续费,但是需要外国证书认证机构给域名注册时留的邮箱发邮件确认,发了几次邮件,仍然没有收到邮件。于是,协商决定在网站下面放一个认证码,让国外访问来确定域名归属。

以下把我在配置过程中遇到的问题总结如下:

1、tomcat下新建目录下文件访问404

接到这个问题,想着很简单,在站点目录下面创建一个文件,然后全路径访问就好了,但是当真的这么做了以后,才发现事情并没有那么简单,检查过权限啊,重启啊,总是404.然后网上查资料,各种回答都有,有的说把web.xml放到新建目录下,照做后,问题

仍然没有解决。咨询了开发后,才知道开发在springMVC.xml下配置了启动tomcat后加载的资源和要拦截的地址(目录地址)。比如我要访问www.baidu.com/.well-known/1.txt,那么我就要在springMVC.xml下添加下面两行内容:

    <!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="com.hengxin.qianee.controller" /> <mvc:annotation-driven /> <mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/skippr/**" location="/skippr/" />
.......
<mvc:resources mapping="/sitemap.txt" location="/" />
<mvc:resources mapping="/sitemap.xsl" location="/" />
<mvc:resources mapping="/silian.txt" location="/" />
<mvc:resources mapping="/.well-known/**" location="/.well-known/" />
<mvc:interceptors>
<!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
<mvc:interceptor>
<mvc:mapping path="/**"/> <!-- 需排除拦截的地址 -->
<mvc:exclude-mapping path="/.well-known/**"/>
<mvc:exclude-mapping path="/css/**"/>
<mvc:exclude-mapping path="/images/**"/>
<mvc:exclude-mapping path="/js/**"/>
<mvc:exclude-mapping path="/skippr/**"/>
<mvc:exclude-mapping path="/account/getCity"/>
<mvc:exclude-mapping path="/account/getAreas"/>

2、使用baidu.com直接访问网站。

原本网站做的跳转,如果输入baidu.com的时候自动跳转到www.baidu.com,但是现在认证方需要实现不要直接跳转,而是直接访问baidu.com/.well-known/1.txt,获取到认证方发来的认证码(这个认证码是事先发过来的,只要放到这个1.txt中即可),而我们网站做的多层跳转,如下图:

配置文件如下:

     server
{
listen ;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server_name www.baidu.com; location ^~/front/aboutUs/aboutUs/
{
proxy_pass http://baidu;
} location /
{
rewrite ^(.*) https://www.baidu.com$1 permanent;
}
} server
{
listen ;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server_name baidu.com; location ^~/front/aboutUs/aboutUs/
{
proxy_pass http://baidu;
}
rewrite ^(.*) http://baidu.com$1 permanent; } server
{
listen ;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server_name www.baidu.com;
ssl on;
ssl_certificate /data/src/baidu.crt;
ssl_certificate_key /data/src/baidu.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1. TLSv1.; location ^~/front/aboutUs/aboutUs/
{
rewrite ^(.*) http://www.baidu.com$1 permanent;
} location /
{
proxy_pass http://baidu;
}
} server
{
listen ;
ssl on;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server_name baidu.com;
ssl_certificate /data/src/baidu.crt;
ssl_certificate_key /data/src/baidu.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1. TLSv1.;
rewrite ^(.*) https://www.baidu.com$1 permanent; location /
{
proxy_pass https://baidu;
}
}

nginx.conf

本来想把其中的baidu.com的跳转给取消掉,结果,测试结果显示跳转太多,无法显示;然后又想把443的跳转和其他的多余的跳转都注销掉,测试结果显示了404,上述两种方法都否决了。

查阅了一番资料,仍然未果。

于是咨询了朋友,他们建议把80和443的虚拟主机配置上别名。但是仔细检查了下配置文件,心想即使配置上别名,仍然会将baidu.com跳转到www.baidu.com;但是仍然抱着破罐破摔的心态,决定尝试下,结果配置完后,居然成功了。

下面是配置过后的配置文件:

 server
{
listen ;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server_name www.baidu.com baidu.com; location ^~/front/aboutUs/aboutUs/
{
proxy_pass http://baidu;
} location /
{
rewrite ^(.*) https://www.baidu.com$1 permanent;
}
} server
{
listen ;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server_name www.baidu.com baidu.com;
ssl on;
ssl_certificate /data/src/baidu.crt;
ssl_certificate_key /data/src/baidu.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1. TLSv1.; location ^~/front/aboutUs/aboutUs/
{
rewrite ^(.*) http://www.baidu.com$1 permanent;
} location /
{
proxy_pass http://baidu;
}
}

注:以上网站网址baidu.com是化名,并非真正网站网址。为保护网站信息,借用而已。

baidu.com直接访问网站,不跳转www.baidu.com的更多相关文章

  1. 通过PHP自带的$_SERVER判断 手机访问网站自动跳转到手机版

    需要有PC版网站和移动版网站,当手机访问域名的时候,通过PHP自带的$_SERVER判断浏览设备并跳转到移动版页面.如果是PC电脑打开网址,则不跳转直接访问pc版. <?php //php判断客 ...

  2. 通过cookies跳过验证码登陆页面,直接访问网站的其它URL

    我每次手动访问去NN网的一家酒店,就不需要登陆,一旦我用脚本打开就会让我登陆,而登陆页面又有验证码,不想识别验证码,所以就想:“通过cookies跳过验证码登陆页面,直接访问网站的其它URL”   转 ...

  3. 手机访问PC网站自动跳转到手机网站代码(转)

    4G时代,手机网站已经非常普遍了,一般手机网站都有一个二级域名来访问,比如 m.16css.com 如果手机直接访问www.16css.com 就是PC网站,在手机上浏览电脑版网站体验非常不好. 如果 ...

  4. 手机访问PC网站自动跳转到手机网站代码

    方法一: <script type="text/javascript"> try { var urlhash = window.location.hash; if (! ...

  5. dede手机访问网站跳转到手机端模板

    如何手机访问的时候跳转到自己的手机端模板,这时候需要一个js跳转代码:当手机访问的时候直接跳转到手机端 那手机端前提要有手机端的模板 <script> if(navigator.platf ...

  6. js判断是手机还是电脑访问网站

    js判断是手机还是电脑访问网站                               <script type="text/javascript"> <!- ...

  7. htaccess文件还可以被用来把访问网站的流量劫持到黑客的网站

    看是否有文件上传操作(POST方法), IPREMOVED--[01/Mar/2013:06:16:48-0600]"POST/uploads/monthly_10_2012/view.ph ...

  8. Nginx禁止直接通过IP地址访问网站以及限制IP登陆某目录(关闭默认站点或空主机头)

    这篇文章主要介绍了Nginx中禁止使用IP访问网站的配置实例,一般在备案时可能需要这种设置,需要的朋友可以参考下   国内因为备案的原因,所有服务器都要禁止使用IP访问网站.否则,如果允许使用IP访问 ...

  9. Nginx禁止直接通过IP地址访问网站

    介绍下在nginx服务器禁止直接通过IP地址访问网站的方法,以避免别人恶意指向自己的IP,有需要的朋友参考下. 有时会遇到很多的恶意IP攻击,在Nginx下可以禁止IP访问. Nginx的默认虚拟主机 ...

随机推荐

  1. Eclipse cdt解决github导入的项目无法打开声明的bug (cannot open declaration)

    概述: 我利用eclipse 的git插件clone github上的远程项目(C++)到本地时遇到一个问题:clone下来的项目没有C++特性,无法使用open declaration等操作,下面是 ...

  2. python与VScode

    用VScode写python是非常方便的.vscode是一个功能非常强大的编辑器,下面介绍大致的使用方法: 下载安装python,配置环境变量. 下载安装VScode(vscode会自动连接pytho ...

  3. springJdbc in 查询,Spring namedParameterJdbcTemplate in查询

    springJdbc in 查询,Spring namedParameterJdbcTemplate in查询, SpringJdbc命名参数in查询,namedParameterJdbcTempla ...

  4. Outlook 2007 实现自动添加密送的方法

    1)在Outlook里面键入Alt+F11打开VBA编辑器:     2)激活左边的工程面板,展开并双击上面的“Project (VbaProject.OTM)/Microsoft Office Ou ...

  5. solaris 下查看某程序所开端口

    普通linux机器下可以用netstat -anp | grep pid即可. solaris下则不同,可以借助pfiles工具,pfiles $pid | grep sock pfiles | gr ...

  6. Ubuntu下安装MySQL及简单操作

    Ubuntu上安装MySQL非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client ...

  7. 使用es6的蹦床函数解决递归造成的堆栈溢出

      首先,我们先定义一个函数,使用递归的思想写求和的方法: function sum(x, y) { if (y > 0) { return sum(x + 1, y - 1); } else ...

  8. 理解Java的反射与内省及其区别

    java的内省机制和反射机制什么区别 内省操作只针对JavaBean,只有符合JavaBean规则的类的成员才可以采用内省API进行操作....而反射则不同,一个类的所有成员都可以进行反射操作. 内省 ...

  9. Windows 下 Tomcat 添加为系统服务

    标记一下,以便以后查看 setclasspath.bat 第一行插入 SET JAVA_HOME=C:\Program Files\Java\jre1.8.0_51 service.bat 第一行插入 ...

  10. mysql 创建merge表方便查询

    SELECT COUNT(*) FROM `comment` SHOW CREATE TABLE `comment` CREATE TABLE `comment1` ( `id` ) NOT NULL ...