1 基于域名的虚拟主机配置
server {
listen 80;
server_name www.zyb.com;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name bbs.zyb.com;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
2 基于端口的虚拟主机配置
server {
listen 8080; #修改此此处端口
server_name www.zyb.com;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
3 基于IP地址的虚拟机
添加IP地址
[root@centos-6-11 ~]# ip add add 10.0.0.30/24 dev eth0
[root@centos-6-11 ~]# ip add add 10.0.0.31/24 dev eth0
[root@centos-6-11 ~]# ip add|grep 10.0.0.
inet 10.0.0.11/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.30/24 scope global secondary eth0
inet 10.0.0.31/24 scope global secondary eth0
server {
listen 10.0.0.30:80;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 10.0.0.31:8080;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
4 虚拟主机的别名配置
server {
listen 80;
server_name bbs.zyb.com zyb.com; #在后面添加即可
location / {
root html/bbs;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
5 Nginx 状态信息配置
[root@centos-6-11 vhost]# vi status.zyb.com.conf
server {
listen 80;
server_name status.zyb.com;
location /status {
stub_status on;
access_log off;
}
}
测试结果: