Welcome! Log In Create A New Profile

Advanced

Reverse proxy to QNAP does not work

November 25, 2015 03:31PM
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
Subject Author Posted

Reverse proxy to QNAP does not work

no.1 November 25, 2015 03:31PM

Re: Reverse proxy to QNAP does not work

Francis Daly November 29, 2015 05:52AM

Re: Reverse proxy to QNAP does not work

no.1 December 16, 2015 03:38PM

Re: Reverse proxy to QNAP does not work

Francis Daly December 30, 2015 12:26PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 158
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready