WFileResource, internal paths, and nginx proxy_pass
Added by Mamadou Babaei over 7 years ago
Hi,
I have a WFileResource which I want to redirect to, from within my app to trigger browser download. Unfortunately, I'll get 404 error as soon as the browser redirects to the resource.
Here is the example code:
WFileResource *fileResource = new Wt::WFileResource(Mime::GetMime(Mime::FileType::Xlsx), filePath.string(), m_parent);
fileResource->suggestFileName(filePath.filename().string());
app->redirect(fileResource->url());
And my Nginx configuration looks like this:
upstream example {
server 127.0.0.1:8888;
}
server {
server_tokens off;
listen 443 default_server ssl http2;
listen [::]:443 default_server ssl http2;
server_name www.example.com;
include /srv/confing/ssl-example-com;
charset utf-8;
merge_slashes on;
root /srv/example.com/www;
location / {
gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
# WebSocket proxying
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://example;
# Remove the http proxy header to address HTTPoxy vulnerability
proxy_set_header Proxy "";
}
# Error Pages
include /srv/confing/error;
# Anti-DDoS
include /srv/confing/anti-ddos;
# Compression
include /srv/confing/compression;
# Static Resource Caching
include /srv/confing/static-resource-caching;
}
Here is the nginx log:
2017/04/14 20:45:31 [error] 77046#100474: *1 open() "/srv/example.com/www/5_BD Info.xlsx_2017_04_07_17_59_21.xlsx"
failed (2: No such file or directory), client: 37.32.114.209, server: www.example.com, request: "GET
/5_BD%20Info.xlsx_2017_04_07_17_59_21.xlsx?wtd=TvmEDnefTvoB5Uxm&request=resource&resource=oe2wx8v&rand=2
HTTP/2.0", host: "www.example.com", referrer: "https://www.example.com/?lang=en"
In contrast to http://redmine.webtoolkit.eu/projects/wt/wiki/Fastcgi_on_nginx#nginx-configuration I don't use FastCGI since I need to proxy websockets through nginx.
I don't have any clue on how to achieve the same results (make internal paths work) as fastcgi_split_path_info with proxy_pass. Is there any easy way to fix this?
Thank you!
Replies (1)
RE: WFileResource, internal paths, and nginx proxy_pass - Added by Wim Dumon over 7 years ago
Hey,
I have no idea why nginx tries to access this URL as a local file, whereas it should be forwarded to http://example. I have little experience with nginx as reverse proxy server - can you enable some debug logging there? Could it be related to the fact that the request is a http/2.0 request?
Best regards,
Wim.