我正在尝试为当前正在开发的节点应用程序设置 Nginx 代理。
我试图只允许列入白名单的 IP 访问主站点,但我有一个 /api 路径,我希望任何 IP 都可以访问该路径。
我尝试过以不同的顺序、嵌套等定义位置块,但没有骰子,目前似乎没有将任何对 /api 的请求传递给代理
upstream node_upstream {
server 127.0.0.1:3000 fail_timeout=0;
}
server {
listen 80;
listen [::]:80;
server_name example.com;
location /api {
allow all;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://node_upstream;
allow 1.2.3.4;
deny all;
}
location /public {
root /path/to/static/files;
}
listen 443 ssl;
... SSL Config here...
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
}
Run Code Online (Sandbox Code Playgroud)