Before you begin make sure selinux closed, or when you are finished configuring virtual hosts, although the site or directory permissions are correct, the result is also a 403 access
nginx web host in three ways:
First, the name-based virtual hosting
(1) creates a corresponding web site directory and program code
[root@web01 ~]# mkdir /data/www/{game,video}
[root@web01 ~]# echo "game" > /data/www/game/index.html
[root@web01 ~]# echo "video" > /data/www/video/index.html
(2) configure different virtual host domain name
[web01 the root @ ~] # CAT /etc/nginx/conf.d/ game.conf
Server {
the listen 80 ;
server_name The game.com;
the root / Data / WWW / Game;
index index.html;
...
}
[the root @ web01 ~] # CAT /etc/nginx/conf.d/ video.conf
Server {
...
the listen 80 ;
server_name video.com;
the root / Data / WWW / Video;
index index.html;
}
most after configuring the virtual host good service restart or reload nginx
(3) modify the hosts file access test
vim /etc/hosts 127.0.0.1 game.com video.com
curl game.com
game
curl video.com
video
Second, IP-based virtual hosts
1, IP-based multi-card multi-way
server {
...
listen 10.0.0.10:80;
...
}
server {
...
listen 10.0.0.11:80;
...
}
2, based on a single IP network adapters way
#添加一个IP [root@web01 ~]# ip addr add 10.0.0.11/24 dev eth0 # 虚拟机配置方案 [root@web01 ~]# cat /etc/nginx/conf.d/addr1.conf server { ... listen 10.0.0.10:80; ... } [root@web01 ~]# cat /etc/nginx/conf.d/addr2.conf server { ... listen 10.0.0.11:80; ... }
三、基于端口的虚拟书记
#仅修改listen监听端口即可, 但不能和系统端口出现冲突
[root@web01 ~]# cat /etc/nginx/conf.d/port1.conf
server {
...
listen 80;
...
}
[root@web01 ~]# cat /etc/nginx/conf.d/port2.conf
server {
...
listen 81;
...
}
[root@web01 ~]# cat /etc/nginx/conf.d/port3.conf
server {
...
listen 82;
...
}