Example of how to set up a third-level domain name in nginx

Example of how to set up a third-level domain name in nginx

Problem Description

By configuring nginx, you can set up an IP address to access different web applications through different ports, but after a long time, the relationship between the port number and the application becomes vague.

For example, http://120.79.79.XX:9001 and foreign.XXX.xin. Although these two URLs point to the same website, the latter is obviously more literal and much better than the former. At the same time, in website SEO, the latter has a higher weight than the former.

Basics

Top-level domains: .com .cn

Second-level domain name: baidu.com sina.com, where baidu and sina are second-level domain names

Third-level domain name: zhidao.baidu.com, zhidao is the third-level domain name

Basic steps

  • Setting up geocoding
  • Configure nginx listening
  • Configure nginx redirect

Create a geocode

The author uses Alibaba Cloud. After logging into the Alibaba Cloud backend, add an A record and fill in the third-level domain name into the host record. For specific filling methods, please refer to the figure below

Configure nginx

Modify the default file in /etc/nginx/sites-aviablable. The complete code is as follows:

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  root /var/www/html/wordpress;
  index index.php index.html index.htm index.nginx-debian.html;

  server_name www.xXXX.xin;

  location / {
    try_files $uri $uri/ =404;
  }
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  }
  location ~ /\.ht {
    deny all;
  }
}
#Serve 2
server {
  listen 80;
  server_name foreign.XXX.xin;
  location / {
    proxy_pass http://120.79.XX.XX:9000/;
  }
}

Both services listen to the same port 80, but the server_name of service 2 remains consistent with the newly set address resolution. Then set proxy_pass to forward the information obtained from port 80 to port 9000.

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.

You may also be interested in:
  • Sample code for configuring secondary domain name in nginx
  • Nginx reverse proxy secondary domain name binding method and precautions
  • Example of configuring personalized secondary domain names and multiple domain names under Nginx server
  • Nginx perfect solution for adding secondary subdomains in batches

<<:  Vue uses Split to encapsulate the universal drag and slide partition panel component

>>:  MySQL 5.7 mysql command line client usage command details

Recommend

Several methods to execute sql files under mysql command line

Table of contents The first method: When the MySQ...

Detailed explanation of nginx upstream configuration and function

Configuration Example upstream backend { server b...

Web2.0: Causes and Solutions of Information Overload

<br />Information duplication, information o...

How MySQL handles implicit default values

Some students said that they encountered the prob...

Tutorial on installing the unpacked version of mysql5.7 on CentOS 7

1. Unzip the mysql compressed package to the /usr...

Steps to install MySQL using Docker under Linux

As a tester, you may often need to install some s...

MySQL uses covering index to avoid table return and optimize query

Preface Before talking about covering index, we m...

How to add Nginx proxy configuration to allow only internal IP access

location / { index index.jsp; proxy_next_upstream...

Can you do all the web page making test questions?

Web page design related questions, see if you can...

Detailed explanation of Linux lsof command usage

lsof (list open files) is a tool to view files op...

Detailed explanation of the process of building and running Docker containers

Simply pull the image, create a container and run...

The whole process record of introducing Vant framework into WeChat applet

Preface Sometimes I feel that the native UI of We...

Docker nginx implements one host to deploy multiple sites

The virtual machine I rented from a certain site ...