只允许前端域访问nginx中的api

vxqlmq5t  于 8个月前  发布在  Nginx
关注(0)|答案(1)|浏览(120)

我在nginx后面安装了api。我只想我的前端域例如https://myfrontend.com访问的api
我试过使用检查$host,但这是相同的server_name

/api {
    # how to do i allow only myfrontend.com to access it?
    proxy_pass http://127.0.0.1;
}

帮助赞赏!

piv4azn7

piv4azn71#

为我解决。

location / {
    if ($http_origin != "https://myfrontend.com") {
        return 403;
    }
    proxy_pass http://127.0.0.1:3000;
}

相关问题