• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Nginx 运维之域名验证的方法示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

各公众平台在配置接口域名时会验证开发者对域名的配置权, 生成随机的文本及字符串,让放置在域名根目录可以通过域名直接访问到即通过验证。

示例为验证域名 abc.com 可以通过根路由访问 6CysNYj8Hb.txt 响应体为字符串 01df2ddab4774ba2676a5563ccb79ffa。

$ curl https://abc.com/6CysNYj8Hb.txt
01df2ddab4774ba2676a5563ccb79ffa

方案一

配置有 root 的 server,直接把随机文档放置在该目录下即可,不需要重启 nginx 服务。

方案二

匹配路由,指定随机文档所在目录, 需要重启 nginx。

location ~* 6CysNYj8Hb\.txt {
 root /data/ftp;
}

方案三(推荐)

匹配路由,直接返回需要验证的随机字符串,需要重启 nginx。

location = /6CysNYj8Hb.txt {
 default_type text/html;
 return 200 '01df2ddab4774ba2676a5563ccb79ffa';
}

参考

Nginx 的 Location 从零开始配置

nginx 配置返回文本或 json

补充:Nginx域名重定向

1、更改配置文件test.com.conf

[root@jimmylinux-001 vhost]# vim test.com.conf

server
{
  listen 80;
  server_name test.com test2.com test3.com;
  index index.html index.htm index.php;
  root /data/wwwroot/test.com;
  if ($host != 'test.com' ) {
    rewrite ^/(.*)$ http://test.com/$1 permanent;
  }

}

2、curl测试

[root@jimmylinux-001 vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@jimmylinux-001 vhost]# /usr/local/nginx/sbin/nginx -s reload

[root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test2.com/index.html -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.1
Date: Thu, 07 Jun 2018 16:47:36 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/index.html

[root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test2.com/admin/index.html -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.1
Date: Thu, 07 Jun 2018 16:48:08 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/admin/index.html

[root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test3.com/admin/index.html/adjlfj -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.1
Date: Thu, 07 Jun 2018 16:48:35 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/admin/index.html/adjlfj

[root@jimmylinux-001 vhost]# curl -x127.0.0.1:80 test4.com/admin/index.html/adjlfj -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Thu, 07 Jun 2018 16:48:43 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持极客世界。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
nginx配置返回文本或json的方法发布时间:2022-02-12
下一篇:
全面解析Nginx到底能做什么发布时间:2022-02-12
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap