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
[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