与这篇文章非常相似的问题:Allowing only local network access in NGINX
我有两个子域在 nginx 上运行。 [www].example.com 和 [vault].example.com。我希望 [vault].example.com 只能从 [www].example.com 访问,所以我试图只允许服务器 ip 访问子域。
按照上面的帖子,我创建了一个 private.conf
allow 192.168.1.0/24;
deny all;
但我不确定应该把include /etc/nginx/private.conf
放在哪里。如果我把它放在 nginx.conf 文件中,它也会阻止 [www].example.com 子域,我不想要那样。我找不到将它放在 /sites-available/vault
文件中的位置的指南,因为没有 http 块,如果我把它放在最后一行,它会再次阻止从 [www].example.com 访问公众。
/etc/nginx/sites-available/vault
server {
location {
...
}
...
}
upstream backend {
...
}
server {
location {
...
}
...
}