Nginx虚拟主机配置

基于域名的服务端: 13  yum -y install gcc-* glibc-* make cmake libtool ncurses-devel* pcre*

   14  ls

   15  tar xvf nginx-0.8.55.tar.gz -C /mnt

   16  cd /mnt/nginx-0.8.55/

   18  ls

   19  ./configure --prefix=/usr/local/nginx

   20  make &&make install

   21  cd /usr/local/nginx/

   22  ls

   23  lsof -i:80查看端口查不到(没开起服务)

   24  sbin/nginx 开启服务

   26  lsof -i:80

   27  cat conf/nginx.conf |grep -v '#' |grep -v '^$'查看并筛选有关配置文件复制

   28  cat conf/nginx.conf |grep -v '#' |grep -v '^$' > conf/nginx.conf删除所有配置

   29  vim conf/nginx.conf粘贴有关配置完从server开始复制7行

编辑修改:###########################domain################################

    server {

        listen       80;

        server_name  www1.baidu.com;

        location / {

            root   /domain1;

            index  index.html index.htm;

        }

}

    server {

        listen       80;

        server_name  www2.baidu.com;

        location / {

            root   /domain2;

            index  index.html index.htm;

        }

}

 

 

   30  mkdir /domain1

   31  mkdir /domain2

   33  echo doamin1:www1 > /domain1/index.html

   34  echo doamin2:www2 > /domain2/index.html

   35  sbin/nginx

   36  killall nginx先杀死进程在开启服务

   37  sbin/nginx

   38  yum -y install bind bind-chroot安装DNS管理包做域名解析服务

   39  cd /var/named/chroot/

   40  vim /etc/named.conf

编辑修改:options {

          listen-on port 53 { any; };

          listen-on-v6 port 53 { ::1; };

          directory       "/var/named";

          dump-file       "/var/named/data/cache_dump.db";

          statistics-file "/var/named/data/named_stats.txt";

          memstatistics-file "/var/named/data/named_mem_stats.txt";

          allow-query     { any; };

          recursion yes;

 

         zone "baidu.com." IN {

         type master;

         file "baidu.com.zone";

};

 

 

 

   41  vim /var/named/baidu.com.zone

 

编辑修改:$TTL 86400

          @ IN SOA www.baidu.com. root (2014081701

  1H

  1M

  1W

  1D

  )

         @ IN NS www.baidu.com.

         www IN A 172.18.43.146

         www1 IN A 172.18.43.146

         www2 IN A 172.18.43.146

 

 

   42  service named start

   43  service httpd start

   44  ifconfig eth0 172.18.43.146

   45  service httpd start

   46  iptables -F

   47  setenforce 0

   50  cd /usr/local/nginx/

   51  killall nginx

   53  sbin/nginx

   55  service named restart

 

 

客户端访问验证:

        iptables -F

        setenforce 0

        ifconfig eth0 172.18.43.147

        vim /etc/resolv.conf

    编辑:nameserver 172.18.43.146

    访问:www1.baidu.com 

          www2.baidu.com

 

 

 

基于端口的服务端:61  vim conf/nginx.conf

 

编辑修改:################################port################################

    server {

        listen      8080;

        server_name  172.18.43.146:8080;

        location / {

            root   /port1;

            index  index.html index.htm;

        }

}

    server {

        listen       8081;

        server_name  172.18.43.146:8081;

        location / {

            root   /port2;

            index  index.html index.htm;

        }

}

 

 

            

                63  mkdir /port1

                64  mkdir /port2

                65  echo port1:8080 > /port1/index.html

                66  echo port2:8081 > /port2/index.html

                71  sbin/nginx

                72  kilall nginx

73  sbin/nginx

 

 

客户端访问验证:

        172.18.43.146:8080

        172.18.43.146:8081

 

 

 

基于ip的服务端:76  vim conf/nginx.conf

 

编辑修改:########################ip#######################################

    server {

        listen       172.18.43.148:80;

        location / {

            root   /ip1;

            index  index.html index.htm;

        }

}

    server {

        listen       172.18.43.149:80;

        location / {

            root   /ip2;

            index  index.html index.htm;

        }

}

}

 

 

   77  sbin/nginx

   78  killall nginx

   79  sbin/nginx

   80  mkdir /ip1

   81  mkdir /ip2

   82  echo ip1:172.18.43.148 > /ip1/index.html

   83  echo ip2:172.18.43.149 > /ip2/index.html

   84  ifconfig eth0:0 172.18.43.148

   85  ifconfig eth0:1 172.18.43.149

 

客户端访问验证:

        http://172.18.43.148

        http://172.18.43.149

posted @ 2017-02-17 11:26  嘲笑世间百态。  阅读(148)  评论(0编辑  收藏  举报