nginx文件服务器根据文件类型判断预览还是下载

发布时间 2023-11-09 09:43:44作者: 朝阳1
 location /file {
    charset utf-8;
    alias /usr/share/nginx/html/files;
    autoindex off;
    autoindex_exact_size off;
    autoindex_localtime on;
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept' always;

    location ~* \.(jpg|png)$ {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
        add_header 'Access-Control-Allow-Headers' ', X-Requested-With, Content-Type, Accept' always;
    }
}