How can I allow access to a single IP address via

2019-01-16 10:53发布

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
1条回答
霸刀☆藐视天下
2楼-- · 2019-01-16 11:42

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;
    }
  }
查看更多
登录 后发表回答