nginx多域名云主机如何配置
要配置Nginx多域名云主机,可以依照以下步骤进行操作:
1. 打开Nginx配置文件,一般位于`/etc/nginx/nginx.conf`还是`/etc/nginx/conf.d/`目录下。
2. 在`http`块中添加以下内容,用于配置云主机:
```
http {
…
server {
listen 80;
server_name example1.com;
location / {
root /var/www/example1; // 指定网站根目录
index index.html index.htm; // 指定默许首页
}
}
server {
listen 80;
server_name example2.com;
location / {
root /var/www/example2;
index index.html index.htm;
}
}
…
}
```
注意替换`example1.com`和`example2.com`为实际的域名,并将`/var/www/example1`和`/var/www/example2`替换为对应的网站根目录。
3. 保存并关闭配置文件,重新加载Nginx配置文件,命令为`sudo service nginx reload`还是`sudo systemctl reload nginx`。
4. 在服务器的DNS配置中,将相应域名指向服务器的IP地址。
现在,你的Nginx服务器已配置好多个云主机,并可以通过区分的域名访问区分的网站。
TOP