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

Detailed explanation of html-webpack-plugin usage

Recently, I used html-webapck-plugin plug-in for ...

How to use async await elegantly in JS

Table of contents jQuery's $.ajax The beginni...

In-depth understanding of asynchronous waiting in Javascript

In this article, we’ll explore how async/await is...

Example of using CSS3 to customize the style of input multiple-select box

Principle: First hide the input element, then use...

Implementation code of html floating prompt box function

General form prompts always occupy the form space...

Solution to the same IP after cloning Ubuntu 18 virtual machine

Preface I recently used a virtual machine to inst...

VMware workstation 12 install Ubuntu 14.04 (64 bit)

1. Installation Environment Computer model: Lenov...

17 excellent web designs carefully crafted by startups

Startups often bring us surprises with their unco...

Solution to Ubuntu cannot connect to the network

Effective solution for Ubuntu in virtual machine ...

How to load the camera in HTML

Effect diagram: Overall effect: Video loading: Ph...

Detailed explanation of the use of bus in Vue

Vue bus mechanism (bus) In addition to using vuex...

A brief explanation of the reasonable application of table and div in page design

At the beginning of this article, I would like to ...

Docker-compose quickly builds steps for Docker private warehouse

Create docker-compose.yml and fill in the followi...

Introduction to who command examples in Linux

About who Displays users logged into the system. ...