gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:51:20 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com