通过nginx反向代理查看内网Spark UI

1.下载nginx_substitutions_filter并解压

git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git

2.安装nginx 

wget http://nginx.org/download/nginx-1.4.2.tar.gz  

3.编译安装 

sudo ./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx.pid  --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module  --with-debug --add-module=/home/spark/ngx_http_substitutions_filter_module/ //这是模块解压的路径

sudo make

sudo make install

4.配置nginx.conf 

upstream  master {
     server 172.16.236.128:8080;
}
upstream  master2 {
     server 172.16.236.128:8088;
}
upstream  master3 {
     server 172.16.236.129:4040;
}


upstream  h102 {
     server 172.16.236.129:8042;
}
upstream  h103 {
     server 172.16.236.130:8042;
}
upstream  h104 {
     server 172.16.236.131:8042;
}
upstream  h105 {
     server 172.16.236.132:8042;
}
upstream  h106 {
     server 172.16.236.133:8042;
}
upstream  h107 {
     server 172.16.236.134:8042;
}
upstream  h108 {
     server 172.16.236.135:8042;
}
upstream  h109 {
     server 172.16.236.136:8042;
}
upstream  h110 {
     server 172.16.236.137:8042;
}
upstream  h111 {
     server 172.16.236.138:8042;
}


server {
listen 8080;
location / {
proxy_pass http://master;
}
}
server {
listen 8088;
location / {
proxy_pass http://master2;
}
}
server {
listen 4040;
location / {
proxy_pass http://master3;
}
}
server {
listen 8042;
location / {
proxy_pass http://h102;
}
}
server {
listen 8043;
location / {
proxy_pass http://h103;
}
}
server {
listen 8044;
location / {
proxy_pass http://h104;
}
}
server {
listen 8045;
location / {
proxy_pass http://h105;
}
}
server {
listen 8046;
location / {
proxy_pass http://h106;
}
}
server {
listen 8047;
location / {
proxy_pass http://h107;
}
}
server {
listen 8048;
location / {
proxy_pass http://h108;
}
}
server {
listen 8049;
location / {
proxy_pass http://h109;
}
}
server {
listen 8050;
location / {
proxy_pass http://h110;
}
}
server {
listen 8051;
location / {
proxy_pass http://h111;
}
}

最后重载配置文件

sudo /usr/local/nginx/sbin/nginx -s reload

通过服务器地址+端口号即可访问内网集群的对应网址

Nginx 反向代理是一种常见的网络架构设计,主要用于负载均衡、URL重定向和内部服务间的通信。在某些场景下,如果想要让内网的服务可以通过公网访问(即内网穿透),你可以按照以下步骤配置 Nginx: 1. **环境准备**: - 确保你已经在服务器上安装了 Nginx。 - 需要有一个公网IP地址,或者已经设置了端口映射(如NAT、DMZ等)。 2. **配置 Nginx**: 在 Nginx 的配置文件(一般为 `nginx.conf` 或 `sites-available/your-site.conf`)中,新建或编辑一个虚拟主机块(server block)。设置如下示例配置: ```nginx server { listen 80; # 公网监听的端口,根据实际情况更改 server_name yourdomain.com; # 替换为你自己的域名 location / { proxy_pass http://your_internal_ip:internal_port; # 内网服务的 IP 和端口 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # 如果需要 SSL/TLS,添加以下内容 # ssl_certificate_path /path/to/certificate; # ssl_certificate_key_path /path/to/key; # 错误页面处理 error_page 502 /502.html; location = /502.html { root /usr/share/nginx/html; # 默认路径,也可以自定义 } } ``` 3. **重启 Nginx**: 修改完配置后,执行 `sudo service nginx reload` 或者 `sudo systemctl restart nginx` 命令使新配置生效。 4. **测试**: 尝试从公网访问 `http://yourdomain.com`,Nginx 应该会转发请求到内网指定的服务器并返回响应。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值