Reverse proxy to QNAP does not work
no.1
nginx-forum at nginx.us
Wed Nov 25 20:31:19 UTC 2015
I've been trying to reach my QNAP NAS from internet via reverse proxy on
Raspberry Pi. Beside the stand alone QNAP a owncloud installation should run
as well on the RPi. The plan was to use subdirectories to access both
(https://example.com/nas and https://example.com/owncloud). Subdomains are
not possible.
Even if I leave out the owncloud installation it won't work to access the
NAS via subdirectory.
It works with “direct access” and proxy_pass:
upstream php-handler {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/owncloud.crt;
ssl_certificate_key /etc/nginx/ssl/owncloud.key;
location / {
proxy_pass http://qnap:8080;
proxy_set_header X-Real-IP $remote_addr;
}
}
But as soon as I try that a rewrite it ends up shortening the url to
https://example.com/cgi-bin/login.html?1448481759 and an 404 error instead
of https://example.com/nas/cgi-bin (with the logon windows from the QNAP
which is show locally if I use https://qnap:8080). location block look
like:
location /nas/ {
rewrite /nas/(.*) /$1 break;
proxy_set_header Accept-Encoding "";
proxy_pass http://qnap:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect https://qnap:8080/ /nas/;
sub_filter '"/' '"/nas/';
sub_filter_once off;
}
Response header on this page says gzip for content-encoding and content-type
text/html (which I've read in another post is often relevant using
sub_filter directives).
If I add a location block before it looks fine, the logon window appears but
I can't logon. “Password or username is wrong”.
location / {
if ($http_referer ~ /nas) {
rewrite ^(.*) /nas$1 permanent;
}
return 404;
}
I try to understand nginx and the directives behind, but it’s really hard to
find „my way“. So at the moment it’s more trial and error and I hope someone
can help.
Kind regs
no.1
_________
my configuration:
- QNAP with latest firmware 4.2.0 (2015/10/23)
- (Standard) Raspbian (Debian Jessie) on a RPi Model B
- nginx 1.6.2 with --with-http_sub_module and
--add-module=/build/nginx-Kaumns/nginx-1.6.2/debian/modules/ngx_http_substitutions_filter_module
- PHP 5.6 mit php-fpm
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,263081,263081#msg-263081
More information about the nginx
mailing list