Home  >  Article  >  Operation and Maintenance  >  How to bind domain name and set root directory to nginx server

How to bind domain name and set root directory to nginx server

PHPz
PHPzforward
2023-05-13 21:10:182319browse

It is very convenient for the nginx server to bind the domain name and set the root directory. First enter the nginx installation directory, then execute vim conf/nginx.conf to open the nginx configuration file and find the

server {
    .....
    .....
  }

code segment. This code It is used to configure the corresponding site. First, we should resolve the domain name to the IP address of our server in the domain name control panel, and then the binding can take effect.

First find the server_name item in our code segment and then Just change the following domain name to the domain name we want to bind

root is the specified root directory, set it to the directory we specify

How to bind domain name and set root directory to nginx server

What if we want to bind multiple domain names, or various second-level domain names, such as hao., tools.; first, resolve the domain name to the server, and then copy the above server{} code as a whole Repeat the paragraph and paste it below. In this way, multiple servers will be constructed as a multi-site configuration. Pay attention to copying the entire brace, and the braces must be symmetrical. There must be a space or line break between the braces and the previous statement in the shell script. This is very difficult. Important things like server { or if () { must be paid attention to. Others are easy to understand. Of course, many integration packages will set up a code virtual host directory such as vhost in the same directory as the configuration file nginx.conf. For binding Define multiple domain names and set up multiple configuration files, such as aa.conf and bb.conf, and then use include vhost/*.conf in nginx.conf; import them all. The introduction is equivalent to writing all the code in nginx.conf. And there is no need to consider the relationship between other directories, nginx.conf shall prevail, which is convenient for management, such as aa.conf;

How to bind domain name and set root directory to nginx server

How to bind domain name and set root directory to nginx server

## Others Rule configuration can also be managed uniformly by creating multiple files as above. After all configurations are completed, save and exit, and then restart the server to take effect.

In addition, listen specifies the site port, which can be used without conflict. It is enough to customize the configuration. Server_name specifies the domain name, index specifies the default homepage, and root specifies the root directory. In this way, you can master these basic configurations

The above is the detailed content of How to bind domain name and set root directory to nginx server. 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