我有一个
express nodejs
应用程序在 ubuntu EC2 的 NGINX 中运行 PM2
和反向代理。
我希望 Nginx 阻止来自所有来源的请求,除非它是 https://example.com。我有上面的配置文件,但它仍然接受任何请求。
server {
listen 80;
listen [::]:80;
server_name api.mysite.com;
location / {
# Proxy request to the backend API
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# Set CORS headers
add_header "Access-Control-Allow-Origin" "https://example.com";
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS";
add_header "Access-Control-Allow-Headers" "Authorization";
}
}
我试过很多次改变。也在 express 中使用 CORS 但没有结果。