How to set up a third-level domain name in nginx

2023-09-11 15:41:36

<p>problem description</p><p>By configuring nginx, you can set an ip address to access different web applications through different ports, but after a long time, the relationship between port numbers and applications becomes blurred.</p><p>For example, http://120.79.79.xx:9001 and foreign.xxx.xin, although both websites point to the same website, the latter is obviously more interesting than the former. At the same time, in website seo, the latter also has a higher weight than the former.</p><p>elementary knowledge</p><p>Top-level domain name: .com.cn</p><p>Second-level domain name: sina.com, baidu.com, in which baidu and sina are second-level domain names.</p><p>Third-level domain name: zhidao is the third-level domain name in zhidao.baidu.com.</p><p>Basic steps</p><p>Set address resolution</p><p>Configure nginx listening</p><p>Configure nginx jump</p><p>Create address resolution</p><p>Alibaba Cloud used by the author, after logging in to the Alibaba Cloud background, adds a record and fills the third-level domain name into the host record. For details, please refer to the following figure.</p><p><img src="https://freeonlinedomain.com/uploads/allimg/Server/20230911/vp4dplvqxw3110.jpg"/></p><p><img src="https://freeonlinedomain.com/uploads/allimg/Server/20230911/kw0qrxjc1ks111.jpg"/></p><p>Configure nginx</p><p>Modify the default file in/etc/nginx/sites-avilable, and the complete code is as follows:</p><p>server { listen 80 default_server; &nbsp;listen [::]:80 default_server; &nbsp;root /var/www/html/wordpress; &nbsp;index &nbsp;index.php &nbsp;index.html &nbsp;index.htm &nbsp;index.nginx-debian.html ; &nbsp;server_name www.xxxx.xin; &nbsp;location / { try_files $uri $uri/ =404; &nbsp;} location ~ .php$ { include snippets/fastcgi-php.conf; &nbsp;fastcgi_pass unix:/run/php/php7.0-fpm.sock; &nbsp;} location ~ /.ht { deny all; }} # Service2server {listen80; &nbsp;server_name foreign.xxx.xin; &nbsp;location / { proxy_pass &nbsp;http://120.79.xx.xx:9000/; }}</p><p>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.</p>


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us