nginx 解決圖片跨域問題

就這樣延續、 發表於 2020-12-04

  server {
    listen 80;
    server_name static.xx.com;
    location ~* \.(html|htm|shtml|zip|rar|doc|docx|xls|xlsx|ppt|ppts|gif|jpg|jpeg|png|bmp|swf|ico|js|css)$ {
                 root /data/htdocs/xx;   
                  add_header Access-Control-Allow-Origin *;
                 add_header Access-Control-Allow-Headers X-Requested-With;
                  add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
       } 

 

重點是新增

標註的紅色區域就是解決圖片跨域訪問如下

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;