码迷,mamicode.com
首页 > 其他好文 > 详细

配置nginx的独立虚拟主机文件

时间:2016-06-28 00:49:31      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:虚拟主机   配置文件   nginx_vhosts.conf   

   主配置文件为nignx.conf,主配置文件包含的所有配置文件统一放入extra目录,虚拟主机的配置文件起名为nginx_vhosts.conf,也可以把每个虚拟主机配置成一个单独的配置文件。

[root@NFS-Serverconf]# pwd

/application/nginx/conf

[root@NFS-Serverconf]# mkdir extra

[root@NFS-Serverconf]# vi nginx.conf  #内容如下

user  nginx  nginx;

worker_processes  8;

error_log  /app/logs/nginx_error.log crit;

pid  logs/nginx.pid;

events {

    use epoll;

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    log_format main  ‘$remote_addr - $remote_user[$time_local] "$request" ‘

                      ‘$status $body_bytes_sent"$http_referer" ‘

                     ‘"$http_user_agent" "$http_x_forwarded_for"‘;

 

     sendfile        on;

     keepalive_timeout  65;

     include extra/nginx_vhosts.conf;  #引用独立虚拟文件

}

[root@NFS-Serverextra]# cat  nginx_vhosts.conf  #内容如下

server {

        listen 80;

        server_name   www.51cto.com  51cto.com;   #域名

       location / {

            root    /data0/www/www;  #站点目录

            index   index.html index.htm;

            access_log  /app/logs/www_access.log main;  #日志文件

        }

   }

        ###

     server {

        listen    80;

        server_name  bbs.51cto.com;

       location / {

            root   /data0/www/bbs;

            index  index.html index.htm;

             access_log/app/logs/bbs_access.log main;

        }

   }

       ###

       server {

        listen       80;

        server_name  blog.etiantian.org ;

       location / {

            root   /data0/www/blog;

            index  index.html index.htm;

              access_log  /app/logs/blog_access.log main;

            }

        }

#以上是把3个虚拟站点目录配置,从nignx.conf分离出来,在extra下建立一个nginx_vhosts.conf。

#也可以从nginx_vhosts.conf虚拟主机文件中分出3个独立的虚拟主机文件:

[root@NFS-Serverextra]# sed -n ‘10,19p‘ nginx_vhosts.conf > bbs.conf

[root@NFS-Serverextra]# sed -n ‘20,30p‘ nginx_vhosts.conf > blog.conf

[root@NFS-Serverextra]# sed -n ‘1,9p’ nginx_vhosts.conf > www.conf

把虚拟主文件分成三个独立的文件之后,在nginx.conf中要分别做三个引入,如下:

 include extra/nginx_vhosts.conf;  #引用独立虚拟文件

 include extra/bbs.conf;

 include extra/blog.conf;

 include extra/www.conf;

    总而言之,有三种虚拟主机配置方式:一种是所以虚拟主机配置都放在nginx.conf中配置;第二种方式,建立extra目录,在该目录下建立一个nginx_vhosts.conf,三个虚拟站点目录配置文件放在该文件中;第三种方式,分别建立三人独立的虚拟主机文件,通过主配置文件来引入。


本文出自 “sky9890” 博客,请务必保留此出处http://sky9896.blog.51cto.com/2330653/1793452

配置nginx的独立虚拟主机文件

标签:虚拟主机   配置文件   nginx_vhosts.conf   

原文地址:http://sky9896.blog.51cto.com/2330653/1793452

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!