Last update at :2024-05-20,Edit by888u
Currently, most of our server WEB environments use the Nginx engine. Our purpose of using servers is to obtain more resources, and the number of websites can be unlimited. We can configure Nginx according to our needs, and we can customize the settings for specific domains, allowing you to run multiple websites on a single server. For each website, we can set the site document root (the directory that contains the website files), create a separate security policy, use a different SSL certificate, and more.
In this article, our host evaluation configures the Nginx engine module in the Debian10 environment.
First, meet basic requirements
Before looking for configuration, we need the server to ensure that the following prerequisites are met:
1. Domain name pointing to our server IP
2. Our server uses Debian mirroring, here we use Debian10
Second, create the directory structure
The document root directory is the directory where domain name website files are stored and served in response to requests. The document root can be any directory on the server.
The examples in this article use the following directory structure:
/var/www/
├── domain1.com
│ └── public_html
├── domain2.com
│ └── public_html
├── domain3.com
│ └── public_html
Basically, we will create a separate directory in the /var/www directory for each domain that we want to host on the server. Within each directory, we will create a public_html directory that will store the domain website files.
Run the following command to create the root directory for the domain example.com:
sudo mkdir -p /var/www/example.com/public_html
Next, create an index.html file in the domain's document root:
sudo nano /var/www/example.com/public_html/index.html
Add some content:
Welcome to example.com
Success! example.com home page!
Authorization:
sudo chown -R www-data: /var/www/example.com
Third, create server module
By default, on Debian systems, Nginx server block configuration files are stored in the /etc/nginx/sites-available directory. To activate the configuration, we need to symlink the file to the /etc/nginx/sites-enabled/ directory.
Open a text editor and create the following server block file:
sudo nano /etc/nginx/sites-available/example.com.conf
Edit:
server {
listen 80;
listen [::]:80;
root /var/www/example.com/public_html;
index index.html;
server_name example.com www.example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
location/{
try_files $uri $uri/ =404;
}
}
The configuration file can be named arbitrarily. We can create it using our own domain name, which is easy to identify. Enable the new server block file by creating a symbolic link from the file to the site-enabled directory:
sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/
Check:
sudo nginx -t
If the following content appears, it means it is normal:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl restart nginx
Restart Nginx to take effect.
In this way, we can completely add the current site. Similarly, if we need to add other sites, the same is true, but the bound domain name directory is different. However, if we use a script one-click package or a WEB panel, there is no need to set it manually like this.
Recommended site search: PHP space recommendation, Chinese domain name, domain name registration, free cloud server for individuals outside mainland China, domain name registration application, website domain name query system, cn domain name, permanent free cloud server address, how to register a website, shared hosting,
发表评论