Reverse proxy to QNAP does not work

Francis Daly francis at daoine.org
Sun Nov 29 10:51:17 UTC 2015


On Wed, Nov 25, 2015 at 03:31:19PM -0500, no.1 wrote:

Hi there,

I don't have a qnap system to test with, so I do not know how the
application responds.

> The plan was to use subdirectories to access both
> (https://example.com/nas and https://example.com/owncloud). Subdomains are
> not possible.

In general, you can only easily reverse proxy things at different levels
in the /url hierarchy, if the upstream application is written to allow
it. (Basically, this means that local links in the application should
not start with / and should not start with http:// or https://.)

There are exceptions.

If these nas and owncloud applications fit the "easy" pattern, then it
should be straightforward. If not, then you can choose to battle it;
or you can choose to change your "no subdomain" rule. Or you can see if
you can reconfigure the nas and owncloud applications to be at different
points in the hierarchy.

>   location / {
>     proxy_pass http://qnap:8080;
>     proxy_set_header X-Real-IP $remote_addr;
>   }

See http://nginx.org/r/proxy_pass for what request is passed to qnap,
when a request comes in to nginx.

> But as soon as I try that a rewrite

Why do you use a rewrite?

I would expect that something like

  location ^~ /nas/ {
    proxy_pass http://qnap:8080/;
    proxy_set_header X-Real-IP $remote_addr;
  }

(note the extra / on the proxy_pass line) should make the correct initial
request to qnap.

There may well be responses that lead to further requests that do not
do what you want; but that's usually what happens when reverse proxying,
and they can be addressed when the details are available.

If it does not Just Work, the next easiest thing (I believe) is to try
to configure the qnap service so that it believes that its base url is
/nas/ and not /, on the local server.

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list