1、vhost配置文件的作用
作用:vhost配置文件的作用是为了将多个server配置文件的信息,单独存放,不过于集中在nginx.conf配置中,这样有用助于故障排除,如配置查看
2、创建vhost文件更夹,并指定加载方法
[root@localhost conf]# pwd
/app/nginx-1.6.3/conf
[root@localhost conf]# mkdir vhost
[root@localhost conf]# vi /app/nginx-1.6.3/conf/nginx.conf #修改nginx.conf的配置文件,增加include目录
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include vhost/*.conf; #增加内容,当nginx启动时,加载vhost目录下的所有conf文件
}
3、把原有nginx配置文件的server字段,复制到default.conf里
[root@localhost conf]# vi /app/nginx-1.6.3/conf/vhost/default.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
备注:后面的server字段的配置文件,就可以在vhost新建conf文件就可以。
转载于:https://blog.51cto.com/12965094/2144965