Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I allow access to a single IP address via Nginx.conf?

Tags:

nginx

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;         }       }     } 
like image 318
MrDerp Avatar asked Dec 08 '11 22:12

MrDerp


People also ask

How do I limit nginx connections?

To limit connections, use the limint_conn directive to set the memory zone to be used and the maximum number of allowed connections as shown in the following configuration snippet. This directive is valid within the HTTP, server, and location contexts. Save the file and close it.


1 Answers

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;     }   } 
like image 90
erkasraim Avatar answered Oct 03 '22 09:10

erkasraim