---
title: " DX2开启X-sendfile后和Nginx的Expire冲突，导致图片不能用附件下载的方式下载"
author: "2002wmj"
date: "2012-05-23T18:38:36Z"
tags: []
categories: ["编程语言"]
slug: "dx2-x-sendfile-nginx-expire"
draft: false
lastmod: "2012-05-23T18:38:36Z"
id: 1539082
url: "https://2002wmj.iteye.com/blog/1539082"
---

原地址：http://www.discuz.net/thread-2312645-1-1.html

我的服务器使用nginx1.1.0  
X-sendfile设置如下

1. location /down {
2. internal;
3. alias    /home/data/bbs/data/attachment/forum;
4. }

*复制代码*

静态文件Expires设置如下

1. location ~* \\.(gif|jpg|jpeg|png|bmp|ico|css|js|swf)$
2. {
3. access\_log off;
4. expires 30d;
5. FileETag on;
6. etag\_format "%X%X";
7. }

*复制代码*

config\_global.php附件下载设置如下：

1. $\_config\['download']\['readmod'] = 4;
2. $\_config\['download']\['xsendfile']\['type'] = '1';
3. $\_config\['download']\['xsendfile']\['dir'] = '/down/';

*复制代码*

现出现这个问题，就是但凡出现在Exipres设置里的文件类型，都无法通过附件的方式下载，但是图片可以直接显示在论坛里，把鼠标移动到图片上以后，出现”下载附件“的链接，点击后就显示找不到附件。如果从Expires设置里去掉相应的后缀，就不会出现这个问题，请官方查看一下具体是什么原因引起的

 

 

自己解决了，在forum\_attachment.php找到

1. $type = intval($xsendfile\['type']);

*复制代码*

在底下加上

1. if($isimage){
2. $type = 0;
3. }

*复制代码*