找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 111|回复: 1

[L/WNAMP] nginx如何限制只允许内网访问

[复制链接]
发表于 2024-2-15 11:06 | 显示全部楼层 |阅读模式

使用 status.example.com 解析到 123.123.666.666 (公网 ip) 后添加如下配置

nginx conf

server {
    listen 80;
    server_name status.example.com;
    charset utf-8;
    location / {
        proxy_pass http://192.168.1.167:3001;
	    proxy_set_header   X-Real-IP $remote_addr;
		proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header   Host $host;
		proxy_set_header   X-Forwarded-Host $host;
		proxy_http_version 1.1;
		proxy_set_header   Upgrade $http_upgrade;
	    proxy_set_header   Connection "upgrade";
    } 
	
 
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

现在想要 限制只允许同内网的机器访问 ,尝试过添加

 # 优先允许内网中的特定 IP 地址
 allow 192.168.0.199; # 或者你想要允许的内网 IP 地址
 # 接着允许特定网段的 IP 范围访问
 allow 192.168.0.0/23;
 # 最后拒绝所有其他 IP 地址
 deny all;

但是测试发现要么都是允许要么都是 403

网络路径是 status.example.com > 123.123.666.666 > 深信服 > 内网机器(nginx)

源文地址:https://www.v2ex.com/t/999454

 楼主| 发表于 2024-2-15 11:07 | 显示全部楼层
各位 ,问题出在防火墙上,外部流量进来的时候被 192.168.0.1 给代理了,导致在应用侧收到的访问 ip 都是 192.168.0.1
```
location /ip {
default_type text/plain;
return 200 $remote_addr;
}
```


让网关同事联系了深信服,处理方案类似于

https://bbs.sangfor.com.cn/forum.php?mod=viewthread&tid=10516
 
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|学习笔记

GMT+8, 2024-5-3 21:00 , Processed in 0.032986 second(s), 15 queries , APCu On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表