nginx 解决图片跨域问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx 解决图片跨域问题相关的知识,希望对你有一定的参考价值。

server
listen 80;
server_name files.ascotprime.com ;
root /var/www/ascotprime/UploadFiles/api;
index index.php index.html index.htm;

location / 
    try_files $uri $uri/ /index.php?$query_string;

location ~ ..(gif|jpg|jpeg|png|bmp|swf)$
add_header Access-Control-Allow-Origin
;
add_header Access-Control-Allow-Methods ‘GET, POST, OPTIONS‘;
add_header Access-Control-Allow-Headers ‘DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,lang,access-token‘;
if ($request_method = ‘OPTIONS‘)
return 204;

    

location ~ \.php 
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods ‘GET, POST, OPTIONS‘;
    add_header Access-Control-Allow-Headers ‘DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,lang,access-token‘;
    if ($request_method = ‘OPTIONS‘) 
        return 204;
    

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index /index.php;
    fastcgi_split_path_info        ^(.+\.php)(/.+)$;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include                       fastcgi_params;

error_log /usr/local/nginx/logs/error.files.ascotprime.com.log;
access_log /usr/local/nginx/logs/access.files.ascotprime.com.log;

以上是关于nginx 解决图片跨域问题的主要内容,如果未能解决你的问题,请参考以下文章

使用nginx代理解决跨域问题

nginx配置解决前端跨域问题

nginx配置反向代理解决vue跨域问题

宝塔面板Nginx反向代理解决跨域问题

Nginx----跨域,防盗链

vue3.0+nginx跨域问题