I want to configure my home network to do everything through my raspberry pi.

My router is, and the pi is They are static IPs.

I have nginx running on the pi, and I'm using dynamic DNS to the router to access from outside. I then have requests to the router forwarded to the pi. In other words, when I type in my dynamic DNS address, I'm directly on the pi's IP, which is being served by nginx.

I then have my nginx config redirecting URLs, such as /router and /media to other devices around my house, which are also on static IPs.

The problem I have is that, for example, on /router there are files and folders that also need to be redirected, eg /images/*.gif and /styes/*.css, and also some *.js and .gif files in the root / folder, some of which are referenced from the files in /style.

So my question is, how do I redirect EVERYTHING that is under to, including rewriting URLS?

See below what I've tried so far. At the moment, this does not work and I either get a 502 relating to circular redirects.


location /router/ {
    sub_filter_once off;
    sub_filter_types text/html;
    sub_filter "" "";

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Host $remote_addr;

    # First try serve as file, then dir, then throw a 404
    # try_files $uri $uri/ =404;

location /style {

location /image {

location ~* \.(gif|jpg|jpeg|js)$ {
    rewrite ^(.*) $1 last;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.