nginx - proxy_pass 的位置不起作用,错误在哪里?
问题描述
它是通过 NGINX 指令重定向端口 3000 的简单 webservce location
,但需要在proxy_pass
. 我使用 UBUNTU 18 LTS 服务器,并逐步执行:
sudo nano /etc/nginx/sites-available/myServce
sudo nginx -t
sudo service nginx restart
还有什么?似乎问题出在myServce NGINX 脚本上,我在下面复制。
配置
NGINX 配置位于/etc/nginx/sites-available/myServce
,
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
。
该解决方案在文件扩展名上创建了其他未解决的问题。
推荐阅读
- stm32 - Rtos 的 Stm32 硬故障异常
- powerapps - 当我的切换按钮为“否”时如何禁用数据卡?
- reactjs - React props - 努力区分联合类型
- r - 当存在某些条件时,如何将观察移动到下一行?
- image-processing - 如何在固定帧的视频中跟踪对象的位置?
- javascript - 避免用 string.replace 替换以前的字母
- python - 如何使用 Selenium e Tor 按下“不可见”按钮,但知道 html ID?
- sql - 如何使用其他列值的连接更新列
- apache - 为多个参数和页面编辑 .htaccess
- opengl - 使用 GLX 时,OpenGL glReadPixels 不适用于 EGL