How to configure Nginx second-level domain name

WBOY
Release: 2023-05-12 23:22:04
forward
4369 people have browsed it

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;
        }
    }

}
Copy after login

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;
        }
    }

}
Copy after login

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

./nginx -s reload
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!