nginx支持跨域访问资源

server {
listen 80;
server_name localhost;

location /static {
   root /var/www/webpage;
   expires 30d;
   add_header Cache-Control public;
   access_log off;

   # 加入如下内容,即可允许跨域访问static资源
   add_header Access-Control-Allow-Origin $http_origin;
   add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
   add_header Access-Control-Allow-Credentials true;
   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-Max-Age 1728000;

}

....

}


欢迎转载,本文地址: https://blog.prodrich.com/detail/40/

带着使命来到世上的你,给他人提供价值,才有价值