搭建同个IP,但使用不同域名访问不同端口的网站
题目说明:基于同一IP的不同端口访问不同的网站(可以通过域名去访问) ip+port1 -> 对应一个域名 ip+port2 -> 对应一个域名 使用域名1我应该访问到 ip+port1对应的内容 使用域名2我应该访问到 ip+port2对应的内容
- 添加一个IP地址,每个人的私有网段个有不同:
nmcli c modify ens160 +ipv4.addresses 192.168.73.148/24
nmcli connection up ens160 # 查看
复制代码
- 安装http服务器
yum install -y httpd
复制代码
- 查看httpd文件结构:
├── conf # 存放的主配置文件
│ ├── httpd.conf
│ └── magic
├── conf.d # 存放额外的配置文件: 必须以.conf为后缀才生效
│ ├── autoindex.conf # 额外的参数文件
│ ├── README # 额外的参数文件
│ ├── userdir.conf # 额外的参数文件
│ └── welcome.conf # 默认首页得配置文件
├── conf.modules.d # 存放有关模块的配置文件, 必须以.conf后缀才生效
│ ├── 00-base.conf
│ ├── 00-dav.conf
│ ├── 00-lua.conf
│ ├── 00-mpm.conf
│ ├── 00-proxy.conf
│ ├── 00-systemd.conf
│ └── 01-cgi.conf
├── logs -> ../../var/log/httpd # logs: 日志存放的位置
├── modules -> ../../usr/lib64/httpd/modules # modules: 指定httpd相关模块存放的路径
└── run -> /run/httpd # run: 运行的一些信息
└── state -> # state: 状态的一些信息
复制代码
- 创建两个不同页面目录,用于存放html等网页信息;并创建首页信息
mkdir /var/www/host1
echo this is port1 > /var/www/host/index.html
mkdir /var/www/host3
echo this is other port of host1 > /var/www/host/index.html
复制代码
- 查看端口使用情况,确保不会有端口占用:
ss -tnl
复制代码
- 修改虚拟主机配置文件:
vim /etc/httpd/conf.d/host.conf
# 内容
<Directory "/var/www">
AllowOverride None # 是否允许额外配置文件
require all granted # 设置客户端的访问权限
</Directory>
Listen 192.168.73.148:500
<VirtualHost 192.168.73.148:500>
DocumentRoot "/var/www/host1" # 主机上被访问网站的主目录
</VirtualHost>
Listen 192.168.73.148:1000
<VirtualHost 192.168.73.148:1000>
DocumentRoot "/var/www/host3"
</VirtualHost>
复制代码
8.安装nginx
yum install -y nginx
复制代码
9.使用nginx实现根据域名进行转口转发
vim /etc/nginx/conf.d/host.conf
# 内容
upstream host1 { # 自定义名称host1的模块
server 192.168.73.148:500; # 访问的真实IP地址+端口号
}
server {
listen 192.168.73.148:80; # 绑定的域名
server_name www.qv147.com; # 绑定的域名
client_max_body_size 1024m;
location / {
proxy_pass http://host1; # # host1和upstream host1模块相对应
}
}
upstream host3 {
server 192.168.73.148:1000;
}
server {
listen 192.168.73.148:80;
server_name www.qv258.com;
client_max_body_size 1024m;
location / {
proxy_pass http://host3;
}
}
复制代码
- 重启httpd服务和nginx服务
systemctl restart httpd
systemctl restart nginx
复制代码
- 修改windows下的C:\Windows\System32\drivers\etc\hosts的文件
192.168.73.148 www.qv147.com
192.168.73.148 www.qv258.com
复制代码
注意:hosts文件不认192.168.73.148:8090的写法,只认IP绑定域名
10. 浏览器访问:
碧蓝幻想: 那是主机名吧,就故障切换那有,自己在mds0和mds1上尝试吧
qq_39509342: 请问 一直是mds0和mds1 后面怎么多出来了mds4和mds5了呀
jinxh23: 集群初始化之后失败了
m_10011: Mount挂载
吴春阳: 很好的文章,有一个小提示: 在执行./configure --disable-server --with-o2ib 之前需要执行 bash autogen.sh 来生成configure 文件