nginx 代理 - 如何允许来自特定 ip 的连接
nginx proxy - how to allow connection from a specific ip
我已经安装了 nginx 并将其设置为正向代理(见附件 nginx.conf)
服务器过载,似乎有人在使用它。
有没有办法限制 nginx 代理只接收来自特定 ips 的请求?
请解释我应该如何更改 nginx.conf 以针对 ip 123.456.123.345
执行此操作
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 8080;
location / {
resolver 8.8.8.8;
proxy_pass http://$http_host$uri$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
这样做:
location / {
allow 123.456.123.345;
deny all;
resolver 8.8.8.8;
proxy_pass http://$http_host$uri$is_args$args;
}
来自docs:
The rules are checked in sequence until the first match is found.
因此,如果 IP 等于 123.456.123.345
,将允许访问,否则 - 拒绝。
如果要允许多个IP,可以在deny all;
之前指定:
allow 123.456.123.345;
allow 345.123.456.123;
deny all;
"location" 指令应该在 'server' 指令中
我已经安装了 nginx 并将其设置为正向代理(见附件 nginx.conf) 服务器过载,似乎有人在使用它。
有没有办法限制 nginx 代理只接收来自特定 ips 的请求?
请解释我应该如何更改 nginx.conf 以针对 ip 123.456.123.345
执行此操作worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 8080;
location / {
resolver 8.8.8.8;
proxy_pass http://$http_host$uri$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
这样做:
location / {
allow 123.456.123.345;
deny all;
resolver 8.8.8.8;
proxy_pass http://$http_host$uri$is_args$args;
}
来自docs:
The rules are checked in sequence until the first match is found.
因此,如果 IP 等于 123.456.123.345
,将允许访问,否则 - 拒绝。
如果要允许多个IP,可以在deny all;
之前指定:
allow 123.456.123.345;
allow 345.123.456.123;
deny all;
"location" 指令应该在 'server' 指令中