Home  >  Article  >  Operation and Maintenance  >  How to configure Nginx second-level domain name

How to configure Nginx second-level domain name

WBOY
WBOYforward
2023-05-12 23:22:044590browse

When a domain name needs to be used in two projects, we need to use the second-level domain name. Configure the second-level domain name in Nginx as follows:

1. The original configuration file is as follows

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

}

This is the decompressed nginx.conf file. It can be seen that nginx is currently listening to port 80, and its service name is localhost. If our domain name is: baidu.com, then we enter: localhost.baidu.com Also accessible.

2. Configure the second-level domain name

For the service name we just understood, if our domain name is: baidu.com, the second-level domain name we need to configure is asurplus.baidu.com. Our configuration file is as follows

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    
    server {
        listen       80;
        server_name  asurplus.baidu.com;

        location / {
            proxy_pass http://127.0.0.1:8081;
        }
    }

}

Go to the sbin directory and execute the command to restart nginx

./nginx -s reload

We have added a new service, the listening port is still 80, and our service name becomes ours Second-level domain name: asurplus, and forwarded to our 8081 port, thus completing the configuration of the second-level domain name.

The above is the detailed content of How to configure Nginx second-level domain name. 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