nginx - 如何通过 Nginx.conf 允许访问单个 IP 地址?

标签 nginx

Nginx、Passenger 和 Rails 在我的 Linode 上运行良好。在启动之前,我想限制访问,以便只有我的 IP 可以查看该网站。

我尝试在 Nginx 中拒绝所有人的访问,只允许访问我的 IP。它确实拒绝所有人的访问,但我无法获得允许工作。我已检查以确保我在 nginx.conf 中指定的 IP 地址是我正确的公共(public) IP。

这是我的 nginx.conf。编辑文件后,我重新启动了 nginx,并测试了一些其他按预期工作的更改(例如,我删除了“拒绝所有”,并且能够按预期访问该网站)。

我做错了什么?

    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

  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 - 如何通过 Nginx.conf 允许访问单个 IP 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8438867/

相关文章:

node.js - Nginx 用于 Node JS 应用程序中的身份验证和授权

wordpress - Nginx WordPress 多站点重写子目录安装规则

ajax - 从 https 重定向到 http?

ssl - Nginx 非 HTTPS 网站重定向到其他 HTTPS 网站

正则表达式截断 nginx 上的字符串

node.js - Nginx 在通过 Docker-compose 运行时找不到上游 Node 应用程序

angularjs - nginx环回反向代理无法访问自定义路径

parse-platform - DigitalOcean 上的解析服务器 - 错误 502

node.js - 将 Nginx 设置为 Nodejs 和 Django 的代理

c# - 使用 Mono 的 Windows 集成身份验证