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 文件就可以.
来源: http://www.bubuko.com/infodetail-2687738.html