Nginx基于IP的虚机主机配置

  • Post author:
  • Post category:Nginx
  • Page Views 631 阅读

1.基于IP的虚机主机在生产环境中很少应用,简单了解即可。

[root@CentOS7 conf]# ip addr                    #查看当前使用的网卡文件
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:27:51:92 brd ff:ff:ff:ff:ff:ff
inet 192.168.244.130/24 brd 192.168.244.255 scope global noprefixroute dynamic ens33
valid_lft 1357sec preferred_lft 1357sec
inet6 fe80::4934:e93d:275d:be3e/64 scope link noprefixroute
valid_lft forever preferred_lft forever

2.在网卡上增加IP

[root@CentOS7 conf]# ip addr add 192.168.0.100/24 dev ens33
[root@CentOS7 conf]# ip add|grep 192.168
inet 192.168.244.130/24 brd 192.168.244.255 scope global noprefixroute dynamic ens33
inet 192.168.0.100/24 scope global ens33
[root@CentOS7 conf]# ping 192.168.0.100
PING 192.168.0.100 (192.168.0.100) 56(84) bytes of data.
64 bytes from 192.168.0.100: icmp_seq=1 ttl=64 time=0.047 ms
64 bytes from 192.168.0.100: icmp_seq=2 ttl=64 time=0.084 ms

3.配置文件

    server {
listen 80;
server_name 192.168.244.130;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name 192.168.0.100;
location / {
root html/www1;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@CentOS7 conf]# mkdir ../html/www1
[root@CentOS7 conf]# echo "www.test.com:800" > ../html/www1/index.html
[root@CentOS7 conf]# ../sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.16.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.16.1/conf/nginx.conf test is successful
[root@CentOS7 conf]# ../sbin/nginx -s reload

[root@CentOS7 conf]# curl 192.168.0.100
www.test.com:800
[root@CentOS7 conf]# curl 192.168.244.130
www.test.com


「 文章如果对你有帮助,请点个赞哦^^ 」 

0