一、服务器概况:
1.1 反向代理服务器,ip:192.168.1.250
1.2 Web1 服务器,ip:192.168.1.100
1.3 Web2 服务器,ip:192.168.1.101
二、配置目标
将1.1通过frp,透传到购买的云服务器,通过公网ip,直接访问 反向代理服务器;反向代理服务器,通过后缀端口的方式,将Web1、Web2反向代理到公网ip,后继设置为通过二级域名的方式,访问Web1、Web2
三、在反向代理服务器安装nginx,并设置反向代理
注:总结了一下,实际上是在nginx上增加了两个虚拟机,并将两个虚拟机设置为了各自代理一个Web服务器
centos8 中, vim /etc/nginx/conf.d/default.conf 需要修改的内容如下
# 下面是虚拟机1的设置
server {
listen 8098 default_server; #采用哪个端口打开Web1
listen [::]:8098 default_server;
server_name web1;
location / {
proxy_pass http://192.168.1.100/; #Web1在局域网内的ip路径,反向代理就是这里配置
}
}
# 下面是虚拟机2的设置
server {
listen 8099 default_server; #采用哪个端口打开Web2
listen [::]:8099 default_server;
server_name web1;
location / {
proxy_pass http://192.168.1.101/; #Web2在局域网内的ip路径
}
}
# 下面是安装完nginx后自带的默认内容
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html; #安装了nginx的服务器默认的web,用的是绝对路径,对照代理看
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
四、实现的效果
1.打开 http://192.168.1.250:8098/
2.打开 http://192.168.1.250:8099/
五、Web1、Web2 也可以不用写在default.conf 中,而是分别编写两个文件 /etc/nginx/conf.d/web1.conf /etc/nginx/conf.d/web2.conf ,将上面代码中的对应内容复制进去就可以了。