跨域请求配置

server {
    listen 80;
    server_name www.aaa.com;
    root /var/www/aaa/dist;
    index index.html;

    location /api {
        add_header 'Access-Control-Allow-Origin' 'http://www.bbb.com';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        add_header 'Access-Control-Allow-Credentials' 'true';
        proxy_pass http://www.bbb.com/api;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
}

server {
    listen 80;
    server_name www.bbb.com;
    root /var/www/bbb;
    index index.html;

    location /api {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
}
posted @ 2023-03-07 21:56  脉望  阅读(38)  评论(0编辑  收藏  举报