How can I allow access to a single IP address via Nginx.conf?
NginxNginx Problem Overview
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.
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.
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).
What am I doing wrong?
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 Solutions
Solution 1 - Nginx
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;
}
}
Solution 2 - Nginx
I know this is an old tread, but you an always use sudo nginx -t
to get a more specific error message.