如何允许通过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屋!