分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

基础运维:基于IP实现网页分流

发布时间:2023-09-06 02:12责任编辑:赖小花关键词:暂无标签
一、说明

想要流量分流,在一个接口上设置多IP的方式,是可以实现的,在互联网上需要访问的域名,一般人并不知道什么是IP,就是知道IP,可能他们理解的IP(知识财产权)跟你理解的IP(互联网协议)并不一样。基于IP的分流,目的在于访问这些IP时打开的网页是一致的。分流网页有很多种,这只是其中的一种而已。

二、多IP设置

1.复制网络配置文件

[root@leo ~]# cd /etc/sysconfig/network-scripts/[root@leo network-scripts]# lsifcfg-ens33 ?ifdown-isdn ?????ifdown-tunnel ?ifup-isdn ???ifup-Teamifcfg-lo ????ifdown-post ?????ifup ??????????ifup-plip ???ifup-TeamPortifdown ??????ifdown-ppp ??????ifup-aliases ??ifup-plusb ??ifup-tunnelifdown-bnep ?ifdown-routes ???ifup-bnep ?????ifup-post ???ifup-wirelessifdown-eth ??ifdown-sit ??????ifup-eth ??????ifup-ppp ????init.ipv6-globalifdown-ippp ?ifdown-Team ?????ifup-ippp ?????ifup-routes ?network-functionsifdown-ipv6 ?ifdown-TeamPort ?ifup-ipv6 ?????ifup-sit ????network-functions-ipv6[root@leo network-scripts]# cp ifcfg-ens33 ifcfg-ens33:1

2.修改配置文件

[root@leo network-scripts]# vim ifcfg-ens33:1TYPE="Ethernet"BOOTPROTO="dhcp"NAME="ens33:1"DEVICE="ens33:1"ONBOOT="yes"IPADDR=192.168.116.100PREFIX=24GATEWAY=192.168.116.255[root@leo network-scripts]# 

3.重启网络服务

[root@leo network-scripts]# systemctl restart network[root@leo network-scripts]# ip a1: 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 forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 ???link/ether 00:0c:29:47:c4:9f brd ff:ff:ff:ff:ff:ff ???inet 192.168.116.129/24 brd 192.168.116.255 scope global noprefixroute dynamic ens33 ??????valid_lft 1798sec preferred_lft 1798sec ???inet 192.168.116.100/24 brd 192.168.116.255 scope global secondary noprefixroute ens33:1 ??????valid_lft forever preferred_lft forever ???inet6 fe80::ab30:473d:fe9e:9d7e/64 scope link noprefixroute ???????valid_lft forever preferred_lft forever[root@leo network-scripts]# 

4.本地测试网络连通性

[C:\~]$ ping 192.168.116.100正在 Ping 192.168.116.100 具有 32 字节的数据:来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64192.168.116.100 的 Ping 统计信息: ???数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),往返行程的估计时间(以毫秒为单位): ???最短 = 0ms,最长 = 0ms,平均 = 0ms[C:\~]$ 

三、网页分流

1.设置网页

[root@leo nginx]# mkdir /server/web/test1[root@leo nginx]# mkdir /server/web/test2[root@leo nginx]# mv /server/web/index.html ?test1/ ?????test2/ ?????[root@leo nginx]# cp /server/web/index.html ?/server/web/test1/[root@leo nginx]# cp /server/web/index.html ?/server/web/test2/[root@leo nginx]# cat /server/web/index.html <h1 align=center>vhost</h1>[root@leo nginx]# vim /server/web/test2/index.html [root@leo nginx]# cat /server/web/test2/index.html <h1 align=center>test2 vhost</h1>[root@leo nginx]# 

2.创建NGINX配置文件

[root@leo nginx]# lsconf ?html ?logs ?sbin[root@leo nginx]# cd conf/[root@leo conf]# lsfastcgi.conf ???????????koi-utf ????????????nginx.conf ??????????uwsgi_paramsfastcgi.conf.default ???koi-win ????????????nginx.conf.default ??uwsgi_params.defaultfastcgi_params ?????????mime.types ?????????scgi_params ?????????win-utffastcgi_params.default ?mime.types.default ?scgi_params.default[root@leo conf]# mkdir vhost[root@leo conf]# vim nginx.confinclude vhost/*.conf; ??#在最后括号上添加[root@leo conf]# lsfastcgi.conf ???????????koi-utf ????????????nginx.conf ??????????uwsgi_paramsfastcgi.conf.default ???koi-win ????????????nginx.conf.default ??uwsgi_params.defaultfastcgi_params ?????????mime.types ?????????scgi_params ?????????vhostfastcgi_params.default ?mime.types.default ?scgi_params.default ?win-utf[root@leo conf]# cd vhost/[root@leo vhost]# lstest1.conf ?test2.conf[root@leo vhost]# cat test1.conf server { ???listen 80; ???server_name 192.168.116.129 ; ???index ??index.html index.htm index.php; ???root ?/server/web/test1 ;}[root@leo vhost]# cat test2.conf server { ???listen 80; ???server_name 192.168.116.100 ; ???index ??index.html index.htm index.php; ???root ?/server/web/test2 ;}[root@leo vhost]# 

3.重启NGINX服务

[root@leo vhost]# /usr/local/nginx/sbin/nginx -s reload如果是第一次启动NGINX服务,执行这条命令:[root@leo vhost]# /usr/local/nginx/sbin/nginx

4.访问网页

5.设置访问同一个网页

[root@leo vhost]# vim /server/web/index.html [root@leo vhost]# cat ?/server/web/index.html <h1 align=center>test1 and test2 share ?web page</h1>[root@leo vhost]# vim test2.conf [root@leo vhost]# vim test1.conf [root@leo vhost]# /usr/local/nginx/sbin/nginx -s reload[root@leo vhost]# cat test1.conf server { ???listen 80; ???server_name 192.168.116.129 ; ???index ??index.html index.htm index.php; ???root ?/server/web ;}[root@leo vhost]# cat test2.conf server { ???listen 80; ???server_name 192.168.116.100 ; ???index ??index.html index.htm index.php; ???root ?/server/web ;}[root@leo vhost]# 

6.访问网页

至此基于IP实现网页分流已完成

基础运维:基于IP实现网页分流

原文地址:http://blog.51cto.com/leoheng/2164558

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved