nginx - NGINX - proxy_pass root 只允许特定 IP 访问
问题描述
我只想允许来自 10.10.10.94 的流量
如果我浏览
http://IP/api:5006
(从允许以外的任何机器)我被拒绝访问,它应该可以正常工作
http://IP:5007我得到网页(虽然 WEB 页面页面中没有显示数据,但某些图表应该只来自允许的主机)
问题:
对于/api
位置访问工作正常,它只允许从允许的 IP,但/
没有限制,可以从任何 IP 访问。
server {
listen 80;
listen [::]:80;
server_name site.com;
client_max_body_size 16M;
return 301 https://$host$request_uri;
}
server {
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name site.com;
client_max_body_size 16M;
ssl_certificate /etc/ssl/certs/star.pem;
ssl_certificate_key /etc/ssl/private/star.key;
location / {
allow 10.10.10.94;
deny 10.10.0.0/16;
proxy_pass http://127.0.0.1:5007/;
}
location /api/ {
allow 10.10.10.94;
deny 10.10.0.0/16;
proxy_pass http://127.0.0.1:5006/;
}
}
解决方案
试试这个位置:
location / {
allow 10.10.10.94/32;
deny all;
proxy_pass http://127.0.0.1:5007/;
}
location /api/ {
allow 10.10.10.94/32;
deny all;
proxy_pass http://127.0.0.1:5006/;
}
推荐阅读
- java - 无循环打印 Arraylist
- c# - 访问窗口大小 xaml DataTemplate WPF
- lua - Redis:原子获取和条件集
- java - systemuid异常中的相同jobid
- c# - ASP.NET MVC Update-Database 命令实体验证在尝试插入带分数的十进制数时失败
- django - 使用 Django 搜索 PostgreSQL 并传递一个 null 或空字符串值
- linux - 无法为 CONFIG_UNDWINDER_ORC=y 生成 ORC 元数据
- ios - 在 swift 中仅使用范围键查询 AWS DynamoDB 服务器
- java - 用java将数据写入mysql
- javascript - 如何获取位于表格单元格中的按钮路径