nginx ip 기반 가상 호스트 실전
하나의 네트워크 카드 여러 개의 ip, 어떻게 하나의 네트워크 카드 에 여러 개의 ip 을 설정 합 니까?
방법 1: ifconfig eth 0: 0 10.0.0.101 / 24 up (ifconfig 방식 으로 ip 를 별명 IP 라 고 설정)
[root@web01 conf]# ifconfig eth0:0 10.0.0.101/24 up
[root@web01 conf]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:79:73:42
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:7342/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2694 errors:0 dropped:0 overruns:0 frame:0
TX packets:1959 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:243597 (237.8 KiB) TX bytes:229882 (224.4 KiB)
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:79:73:42
inet addr:10.0.0.101 Bcast:10.0.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr 00:0C:29:79:73:4C
inet addr:172.16.1.8 Bcast:172.16.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:734c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:154 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:9398 (9.1 KiB)
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:65536 Metric:1
RX packets:129 errors:0 dropped:0 overruns:0 frame:0
TX packets:129 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11352 (11.0 KiB) TX bytes:11352 (11.0 KiB)
관리자 m01 위 에 ping 통 할 수 있 습 니까?
[root@m01 ~]# ping 10.0.0.101 -c4
PING 10.0.0.101 (10.0.0.101) 56(84) bytes of data.
64 bytes from 10.0.0.101: icmp_seq=1 ttl=64 time=0.421 ms
64 bytes from 10.0.0.101: icmp_seq=2 ttl=64 time=0.416 ms
64 bytes from 10.0.0.101: icmp_seq=3 ttl=64 time=0.384 ms
64 bytes from 10.0.0.101: icmp_seq=4 ttl=64 time=0.397 ms
--- 10.0.0.101 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.384/0.404/0.421/0.025 ms
방법 2: 보조 IP 설정 ip addr add 10.0.0.102 / 24 dev eth 0 label eth 0: 1 (표정 이 없 는 label ifconifg 는 볼 수 없습니다)
[root@web01 conf]# ip addr add 10.0.0.102/24 dev eth0 label eth0:1
[root@web01 conf]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:79:73:42
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:7342/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2920 errors:0 dropped:0 overruns:0 frame:0
TX packets:2103 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:262933 (256.7 KiB) TX bytes:247258 (241.4 KiB)
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:79:73:42
inet addr:10.0.0.101 Bcast:10.0.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:79:73:42
inet addr:10.0.0.102 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr 00:0C:29:79:73:4C
inet addr:172.16.1.8 Bcast:172.16.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:734c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:154 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:360 (360.0 b) TX bytes:9398 (9.1 KiB)
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:65536 Metric:1
RX packets:129 errors:0 dropped:0 overruns:0 frame:0
TX packets:129 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11352 (11.0 KiB) TX bytes:11352 (11.0 KiB)
ip add 로 ip 의 별명 과 보조 ip 의 차 이 를 알 수 있 습 니 다.
[root@web01 conf]# ip add
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:79:73:42 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.101/24 brd 10.0.0.255 scope global secondary eth0:0
inet 10.0.0.102/24 scope global secondary eth0:1
inet6 fe80::20c:29ff:fe79:7342/64 scope link
valid_lft forever preferred_lft forever
3: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:79:73:4c brd ff:ff:ff:ff:ff:ff
inet 172.16.1.8/24 brd 172.16.1.255 scope global eth1
inet6 fe80::20c:29ff:fe79:734c/64 scope link
valid_lft forever preferred_lft forever
관리자 m01 에 가서 보조 ip 주소 가 통 하 는 지 확인 합 니 다.
[root@m01 ~]# ping -c4 10.0.0.102
PING 10.0.0.102 (10.0.0.102) 56(84) bytes of data.
64 bytes from 10.0.0.102: icmp_seq=1 ttl=64 time=1.65 ms
64 bytes from 10.0.0.102: icmp_seq=2 ttl=64 time=0.330 ms
64 bytes from 10.0.0.102: icmp_seq=3 ttl=64 time=0.379 ms
64 bytes from 10.0.0.102: icmp_seq=4 ttl=64 time=0.318 ms
--- 10.0.0.102 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 0.318/0.670/1.655/0.569 ms
2 nginx 프로필 수정
[root@web01 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 10.0.0.8:80;
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
}
server {
listen 10.0.0.101:80;
server_name www.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
server {
listen 10.0.0.102:80;
server_name www.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
}
}
[root@web01 conf]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
[root@web01 conf]# /application/nginx/sbin/nginx -s reload
2.1 m01 관리자 에서 검증
[root@m01 ~]# curl 10.0.0.8
www
[root@m01 ~]# curl 10.0.0.101
www
101 이 잘못된 것 을 발견 한 이 유 는 부 드 럽 고 우아 하 게 재 부팅 되 지 않 을 때 가 있 습 니 다.웹 01 기기 에서 nginx 서 비 스 를 닫 고 nginx 서 비 스 를 시작 합 니 다.
[root@web01 conf]# /application/nginx/sbin/nginx -s stop
[root@web01 conf]# /application/nginx/sbin/nginx
관리자 m01 에서 계속 검증
[root@m01 ~]# curl 10.0.0.8
www
[root@m01 ~]# curl 10.0.0.101
bbs
[root@m01 ~]# curl 10.0.0.102
blog
위 에서 이미 검증 에 성공 했다.
요약:
ip 설정 (ifconfig 는 별명 ip 주 소 를 설정 하고 ip addr 는 보조 ip 주 소 를 설정 합 니 다)
ifconfig eth0:0 10.0.0.101/24 up
ip addr add 10.0.0.102/24 dev eth0 label eth0:1
ip 삭제
ifconfig eth0:0 down
ip addr del 10.0.0.102/24 dev eth0 label eth0:1
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
용감한 바로 가기 및 우분투 응용 프로그램안녕하세요 여러분, 이 기사에서는 모든 사이트에서 pwa를 생성하고 실행기 응용 프로그램으로 추가하는 방법을 설명하고 싶습니다. 일부 웹사이트는 PWA로 설치를 허용하지 않지만 유사한 애플리케이션을 원합니다. 1. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.