宝塔Nginx配置只允许指定网址访问接口

功能描述:宝塔上做了一个接口,只允许指定的网址访问这个接口的权限,其他接口访问报错!

方法一:允许一个域名访问

add_header Access-Control-Allow-Origin https://example.com;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";

方法二:允许多个域名访问

add_header Access-Control-Allow-Origin "https://example.com, https://sub.example.com";
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";