Nginx operation and maintenance domain name verification method example

Nginx operation and maintenance domain name verification method example

When configuring the interface domain name, each public platform will verify the developer's configuration rights over the domain name, generate random text and strings, and allow those placed in the domain name root directory to be directly accessed through the domain name, thus passing the verification.

The example verifies that the domain name abc.com can access 6CysNYj8Hb.txt through the root route. The response body is the string 01df2ddab4774ba2676a5563ccb79ffa.

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

Solution 1

For a server with root, you can simply place random documents in this directory without restarting the nginx service.

Solution 2

Match the route, specify the directory where the random document is located, and restart nginx.

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

Option 3 (recommended)

Match the route and directly return the random string that needs to be verified. You need to restart nginx.

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

refer to

Nginx Location configuration from scratch

nginx configuration returns text or json

Supplement: Nginx domain name redirection

1. Change the configuration file 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 test

[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

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Nest.js hashing and encryption example detailed explanation

>>:  How to recover accidentally deleted table data in MySQL (must read)

Recommend

How to reference external CSS files and iconfont in WeChat applet wxss

cause The way to import external files into a min...

vue.js downloads pictures according to picture url

Recently, when I was working on a front-end vue.j...

Vue uses Baidu Maps to realize city positioning

This article shares the specific code of Vue usin...

Secondary encapsulation of element el-table table (with table height adaptation)

Preface During my internship at the company, I us...

HTML Editing Basics (A Must-Read for Newbies)

Open DREAMWEAVER and create a new HTML. . Propert...

CSS style to center the HTML tag in the browser

CSS style: Copy code The code is as follows: <s...

Summary of Linux nc command

NC's full name is Netcat (Network Knife), and...

How to introduce img images into Vue pages

When we learn HTML, the image tag <img> int...

Linux automatically deletes logs and example commands from n days ago

1. Delete file command: find the corresponding di...

Mysql: The user specified as a definer ('xxx@'%') does not exist solution

During the project optimization today, MySQL had ...

Use SQL statement to determine whether the record already exists before insert

Table of contents Determine whether a record alre...

Detailed explanation of how to easily switch CSS themes

I recently added a very simple color scheme (them...

4 solutions to mysql import csv errors

This is to commemorate the 4 pitfalls I stepped o...

MySQL 5.7.18 winx64 installation and configuration method graphic tutorial

The installation of compressed packages has chang...

Detailed explanation of how to use Node.js to implement hot reload page

Preface Not long ago, I combined browser-sync+gul...