在nginx服务器

时间:2015-06-18 22:28:28

标签: nginx

我整天都在搜索这个,而不是找到解决方案。这是问题所在: 我的虚拟机正在为我的php应用程序运行带有nginx服务器的ubuntu。我的应用程序工作正常,除了我无法在浏览器中查看或下载PDF文件。

我将尝试描述我的大多数配置,以帮助我解决此问题:

nginx 1.6.2 php 5.5.26

我的/etc/nginx/nginx.conf:

user www-data;
worker_processes 1;
worker_rlimit_nofile 1024;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  access_log  /var/log/nginx/access.log;
  sendfile    on;
  server_tokens on;
  types_hash_max_size 1024;
  types_hash_bucket_size 512;
  server_names_hash_bucket_size 64;
  server_names_hash_max_size 512;

  keepalive_timeout  65;
  tcp_nodelay        on;

  gzip         on;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;

}

我的/etc/nginx/sites-available/app.conf:

server {
    listen    80;
    server_name   app.dev;
    client_max_body_size 1m;
    root /_dev/www/app.com.br/public_html;
    index  index.html index.htm index.php;
    charset   UTF-8;

    access_log    /etc/nginx/www.access.log;
    error_log     /etc/nginx/www.error.log;

    location / {

      root  /_dev/www/app.com.br/public_html;
      try_files $uri $uri/ index.php;
      index  index.html index.htm index.php;
    }

    location ~ \.php$ {

      root  /_dev/www/app.com.br/public_html;
      fastcgi_index index.php;
      fastcgi_split_path_info ^(.+\.php)(/.*)$;
      try_files $uri $uri/ index.php /index.php$is_args$args;
      include /etc/nginx/fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      fastcgi_param APP_ENV dev;
   }

    location ~* (.*\.pdf) {
        types { application/octet-stream .pdf; }
        default_type application/octet-stream;
    }

    sendfile off;
  }

当我单击触发脚本以获取pdf文件的按钮时,响应头是:

Cache-Control:private, must-revalidate, post-check=0, pre-check=0, max-age=1
Connection:keep-alive
Content-Description:File Transfer
Content-Disposition:attachment; filename="romaneio.pdf"
Content-Transfer-Encoding:binary
Content-Type:application/pdf
Date:Thu, 18 Jun 2015 21:59:18 GMT
Expires:Sat, 26 Jul 1997 05:00:00 GMT
Last-Modified:Thu, 18 Jun 2015 21:59:18 GMT
Pragma:public
Server:nginx/1.6.2
Transfer-Encoding:chunked

但是浏览器不会打开它或下载它。它可以是什么?谢谢大家!

编辑:我从ajax响应中获取的控制台日志显示了一堆东西,看起来像是PDF文件代码,为什么浏览器无法打开或下载呢?

编辑2:好吧,经过彻底的研究,我发现tcpdf与ajax调用不兼容,对允许ajax调用的优秀pdf库有任何想法吗?

0 个答案:

没有答案