利用include功能优化nginx的配置文件
-
[root@lnmp 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;
-
#nginx vhosts config
-
include extra/www.conf;
-
include extra/bbs.conf;
-
include extra/blog.conf;
-
}
写配置文件
-
[root@lnmp conf]# mkdir extra
-
[root@lnmp conf]# sed -n '18,25p' nginx.conf.base-name >extra/bbs.conf
-
[root@lnmp conf]# cat extra/bbs.conf
-
server {
-
listen 80;
-
server_name bbs.etiantian.org;
-
location / {
-
root html/bbs;
-
index index.html index.htm;
-
}
-
}
-
[root@lnmp conf]# sed -n '26,33p' nginx.conf.base-name >extra/blog.conf
-
[root@lnmp conf]# cat extra/blog.conf
-
server {
-
listen 80;
-
server_name blog.etiantian.org;
-
location / {
-
root html/blog;
-
index index.html index.htm;
-
}
-
}
-
[root@lnmp conf]# cat extra/www.conf
-
server {
-
listen 80;
-
server_name www.etiantian.org;
-
location / {
-
root html/www;
-
index index.html index.htm;
-
}
-
}
重启服务
-
[root@lnmp conf]# /application/nginx/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
-
[root@lnmp conf]# /application/nginx/sbin/nginx -s reload
测试
-
[root@lnmp conf]# curl www.etiantian.org
-
www.etiantian.org
-
[root@lnmp conf]# curl bbs.etiantian.org
-
bbs.etiantian.org
-
[root@lnmp conf]# curl blog.etiantian.org
-
blog.etiantian.org
nginx虚拟主机别名的配置
-
[root@lnmp conf]# cat extra/www.conf
-
server {
-
listen 80;
|