Home  >  Article  >  Operation and Maintenance  >  How to set a third-level domain name in nginx

How to set a third-level domain name in nginx

WBOY
WBOYforward
2023-05-23 17:31:061786browse

Problem Description

By configuring nginx, you can set an IP address to access different web applications through different ports. However, after a long time, the relationship between the port number and the application will become Very blurry.

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 meaningless and much better than the former. At the same time, in website SEO, the latter also has a higher weight than the former.

Basic knowledge

Top-level domain name: .com .cn

Second-level domain name: baidu.com sina.com, among which baidu and sina are Second-level domain name

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

Basic steps

  • Set up address resolution

  • Configure nginx listening

  • Configure nginx jump

Create Address resolution

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

How to set a third-level domain name in nginx

How to set a third-level domain name in nginx

Configure nginx

Modify /etc/nginx/sites-aviablable default file, 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;
  }
}
#服务2
server {
  listen 80;
  server_name foreign.xxx.xin;
  location / {
    proxy_pass http://120.79.xx.xx:9000/;
  }
}

Both services are listening on the same port 80, but the server_name of service 2 is 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 detailed content of How to set a third-level domain name in nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete