nginx基于端口和ip配置

1、基于端口
[root@nginx conf]# cat nginx.conf  
error_log  logs/error.log error;
worker_processes  2;
events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';    


        server {
        listen       8000;
        server_name  www.wolf.com;
        location / {
            root   html/www;
            index  index.html index.htm;
            access_log logs/www_access.log main;
        }
    }
        server {
        listen       8001;
        server_name  bbs.wolf.com;
        location / {
            root   html/bbs;
            index  index.html index.htm;
            access_log logs/bbs_access.log;
        }
    }
        server {
        listen       8002;
        server_name  blog.wolf.com;
        location / {
            root   html/blog;
            index  index.html index.htm;
            access_log logs/blog_access.log;
        }
    }


##status
   server {
        listen       8004;
        server_name  status.wolf.com;
        location / {
            stub_status on;
            access_log off;
        }
    }
}
[root@nginx conf]# ../sbin/nginx -t
nginx: the configuration file /data/nginx1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx1.8.1/conf/nginx.conf test is successful
[root@nginx conf]# ../sbin/nginx -s reload
测试
ie或者curl


2、基于ip地址 
手动添加ip
[root@nginx conf]# ifconfig eth0:0 192.168.3.60/24 up  
[root@nginx conf]# ifconfig eth0:1 192.168.3.61/24 up  
[root@nginx conf]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:12:99:D4  
          inet addr:192.168.3.49  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe12:99d4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:792652 errors:0 dropped:0 overruns:0 frame:0
          TX packets:460481 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:972250327 (927.2 MiB)  TX bytes:92493014 (88.2 MiB)


eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:12:99:D4  
          inet addr:192.168.3.60  Bcast:192.168.3.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:12:99:D4  
          inet addr:192.168.3.61  Bcast:192.168.3.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:58 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:4962 (4.8 KiB)  TX bytes:4962 (4.8 KiB)


pan0      Link encap:Ethernet  HWaddr A2:25:DF:9D:1A:0F  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
配置文件修改
[root@nginx conf]# cat nginx.conf  


error_log  logs/error.log error;
worker_processes  2;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';    


        server {
        listen       192.168.3.49:80;
        server_name  www.wolf.com;
        location / {
            root   html/www;
            index  index.html index.htm;
            access_log logs/www_access.log main;
        }
    }
        server {
        listen       192.168.3.60:80;
        server_name  bbs.wolf.com;
        location / {
            root   html/bbs;
            index  index.html index.htm;
            access_log logs/bbs_access.log;
        }
    }
        server {
        listen       192.168.3.61:80;
        server_name  blog.wolf.com;
        location / {
            root   html/blog;
            index  index.html index.htm;
            access_log logs/blog_access.log;
        }
    }


##status
   server {
        listen       8004;
        server_name  status.wolf.com;
        location / {
            stub_status on;
            access_log off;
        }
    }
}
[root@nginx conf]# ../sbin/nginx -t
nginx: the configuration file /data/nginx1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx1.8.1/conf/nginx.conf test is successful
[root@nginx conf]# ../sbin/nginx -s reload
测试
ie或者curl
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值