这是通过NGINX location
指令重定向的端口3000上的简单webservce,但需要在proxy_pass
之前添加MIME接受。我使用img UBUNTU 18 LTS服务器,并逐步进行操作:
sudo nano /etc/nginx/sites-available/myServce
sudo nginx -t
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;
}
}
参考测试,一切正常:
curl http://myServce.etc:3000/
curl http://myServce.etc:3000/t?limit=10
为了模拟在test2上的预期结果,使用了curl --header "Accept: text/csv" http://myServce.etc:3000/t?limit=10
并且还可以正常工作。
对已实现的重定向器的类似测试,全部都是错误:
curl http://myServce.etc/_sql.csv/
返回502错误的网关。curl http://myServce.etc/_sql.csv/t?limit=10
返回502错误的网关。有效的解决方案,
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。