proxy_pass的位置不起作用,错误出在哪里?

问题描述 投票:0回答:1

这是通过NGINX location指令重定向的端口3000上的简单webservce,但需要在proxy_pass之前添加MIME接受。我使用img UBUNTU 18 LTS服务器,并逐步进行操作:

  1. sudo nano /etc/nginx/sites-available/myServce
  2. sudo nginx -t
  3. sudo service nginx restart

还有什么?似乎问题出在myServce NGINX脚本上,我在下面复制了。


配置

[/etc/nginx/sites-available/myServce处的NGINX配置,

server {
    root /var/www/myServce/html;
    index index.php index.html index.htm;
    server_name sub1.myServce.etc;

    location ~ ^/_sql.csv/(.*) {
      proxy_set_header Host $host;  # suppose sub1.myServce.etc
      proxy_set_header Accept 'text/csv';
      proxy_pass  http://localhost:3000/$1; # same when sub1.myServce.etc
    }
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_read_timeout 900;
    }
}

测试

参考测试,一切正常:

  1. curl http://myServce.etc:3000/
  2. curl http://myServce.etc:3000/t?limit=10

为了模拟在test2上的预期结果,使用了curl --header "Accept: text/csv" http://myServce.etc:3000/t?limit=10并且还可以正常工作。

对已实现的重定向器的类似测试,全部都是错误:

  1. [curl http://myServce.etc/_sql.csv/返回502错误的网关。
  2. [curl http://myServce.etc/_sql.csv/t?limit=10返回502错误的网关。
nginx
1个回答
0
投票

有效的解决方案,

location /_sql.csv/ {
   proxy_set_header Host $host;
   # add_header Content-Disposition 'attachment; filename="$request_filename.csv"';
   proxy_set_header Accept 'text/csv';
   proxy_pass http://localhost:3000/;
}

它绕过_sql.csv之后的所有字符串。


解决方案创建了其他open problem on filename extension

© www.soinside.com 2019 - 2024. All rights reserved.