标签:system available drive 配置 标识 sans listen and lin
Nginx 虚拟主机
虚拟主机:把一台物理服务器划分成多个“虚拟”的服务器,每一个虚拟主机都可以有独立的域名和独立的目录
Nginx 虚拟主机配置
通过 nginx.conf 中的 server 节点指定,要想设置多个虚拟主机,配置多个 server节点即可
可通过三种方式配置虚拟主机
基于域名
基于端口
基于 IP
基于域名
我们设置下面这三个域名
pic.example.com
dami01.example.com
dami02.example.com
修改 hosts 文件
Windows host 文件位于 C:\Windows\System32\drivers\etc
Ip 地址是 Nginx 服务器所在地址
192.168.1.180 pic.example.com
192.168.1.180 dami01.example.com
192.168.1.180 dami02.example.com
修改 Nginx 配置文件
增加 server 字段
server {
listen 80;
server_name pic.example.com;
root /var/www/html/vhost/pic.example.com;
}
server {
listen 80;
server_name dami01.example.com;
root /var/www/html/vhost/dami01.example.com;
}
server {
listen 80;
server_name dami02.example.com;
root /var/www/html/vhost/dami02.example.com;
}
Nginx 服务器新建对应根目录
$ mkdir -p /var/www/html/vhost/pic.example.com
$ mkdir -pv /var/www/html/vhost/dami0{1..2}.example.com
拷贝 index.html 到对应目录并修改
[root@localhost dami01.example.com]# cat index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to dami01!</h1> ##修改成对应主机,便于标识
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
剩余两台主机参考上面dami01,这里不再赘述
重启 Nginx
$ ./sbin/nginx -s reload
标签:system available drive 配置 标识 sans listen and lin
原文地址:https://www.cnblogs.com/guarderming/p/10396681.html