如何允许通过 Nginx.conf 访问单个 IP 地址? [英] How can I allow access to a single IP address via Nginx.conf?
问题描述
Nginx、Passenger 和 Rails 在我的 Linode 上运行良好.在我启动之前,我想限制访问,以便只有我的 IP 可以查看该站点.
Nginx, Passenger, and Rails are running beautifully on my Linode. Before I launch, I'd like to restrict access so only my IP can view the site.
我试图拒绝所有人访问,并只允许访问我在 Nginx 中的 IP.它确实拒绝访问所有人,但我无法获得允许工作.我已经检查以确保我在 nginx.conf 中指定的 IP 地址是我正确的公共 IP.
I've tried to deny access to all, and allow access to only my IP in Nginx. It does deny access to all, but I can't get the allow to work. I have checked to ensure the IP address I'm specifying in nginx.conf is my correct public ip.
这是我的 nginx.conf.编辑完文件后,我重新启动了 nginx,并测试了其他一些按预期工作的更改(例如,我删除了拒绝全部并能够按预期访问该站点).
Here's my nginx.conf. I've restarted nginx after editing the file, and tested some other changes which worked as expected (for instance, I removed deny all and was able to access the site, as expected).
我做错了什么?
http {
passenger_root /path/to/passenger-3.0.11;
passenger_ruby /path/to/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name www.foo.bar;
root /path/to/rails/public/;
passenger_enabled on;
location / {
allow my.public.ip.here;
deny all;
}
}
}
推荐答案
修改你的 nginx.conf
modify your nginx.conf
server {
listen 80;
server_name www.foo.bar;
location / {
root /path/to/rails/public/;
passenger_enabled on;
allow my.public.ip.here;
deny all;
}
}
这篇关于如何允许通过 Nginx.conf 访问单个 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!