Home >Operation and Maintenance >Nginx >How does Nginx configure a site with multiple domain names?

How does Nginx configure a site with multiple domain names?

PHPz
PHPzforward
2023-05-20 08:19:053584browse

Configure multiple domain names for one site

server {     listen       80;     server_name  ops-coffee.cn b.ops-coffee.cn; }

server_name can be followed by multiple domain names, and separate multiple domain names with spaces

Configure multiple sites for one service

server {     listen       80;     server_name  a.ops-coffee.cn;      location / {         root /home/project/pa;         index index.html;     } }  server {     listen       80;     server_name  ops-coffee.cn b.ops-coffee.cn;      location / {         root /home/project/pb;         index index.html;     } }  server {     listen       80;     server_name  c.ops-coffee.cn;      location / {         root /home/project/pc;         index index.html;     } }

Based on Nginx virtual host configuration, Nginx has three types of virtual hosts

IP-based virtual host: You need to have multiple addresses on your server, and each site corresponds to a different address , this method is rarely used

Port-based virtual host: Each site corresponds to a different port. When accessing, use the ip:port method to access. You can modify the listen port to use

Virtual host based on domain name: The most widely used method. In the above example, virtual host based on domain name is used. The prerequisite is that you have multiple domain names corresponding to each site. Just fill in different domain names for server_name

The above is the detailed content of How does Nginx configure a site with multiple domain names?. 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