[iyunv@web01 conf]# mkdir extra
[iyunv@web01 conf]# vim nginx.conf
[iyunv@web01 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include extra/www.conf;
include extra/bbs.conf;
include extra/blog.conf;
}
[iyunv@web01 conf]# cp nginx.conf.20170820 extra/a
[iyunv@web01 conf]# cd extra/
[iyunv@web01 extra]# sed -n "18,25p" a
server {
listen 80;
server_name bbs.iyunv.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
[iyunv@web01 extra]# sed -n "18,25p" a>bbs.conf
[iyunv@web01 extra]# sed -n "10,17p" a
server {
listen 80;
server_name www.iyunv.org;
location / {
root html/www;
index index.html index.htm;
}
}
[iyunv@web01 extra]# sed -n "10,17p" a >www.conf
[iyunv@web01 extra]# sed -n "26,33p" a
server {
listen 80;
server_name blog.iyunv.org;
location / {
root html/blog;
index index.html index.htm;
}
}
[iyunv@web01 extra]# sed -n "26,33p" a >blog.conf
[iyunv@web01 extra]# rm -f a
这样就生成了3个虚拟主机
[iyunv@web01 extra]# cat www.conf
server {
listen 80;
server_name www.iyunv.org;
location / {
root html/www;
index index.html index.htm;
}
}
[iyunv@web01 extra]# cat bbs.conf
server {
listen 80;
server_name bbs.iyunv.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
[iyunv@web01 extra]# cat blog.conf
server {
listen 80;
server_name blog.iyunv.org;
location / {
root html/blog;
index index.html index.htm;
}
}
虚拟主机已包含在配置文件里面了
[iyunv@web01 extra]# cat ../nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include extra/www.conf;
include extra/bbs.conf;
include extra/blog.conf;
}
检查语法:
[iyunv@web01 extra]# ../../sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful