txtsd
txtsd

Reputation: 181

nginx reverse proxy 404s on caching static content

I'm trying to use nginx as a reverse proxy for ZNC's webadmin. It works fine, when I don't cache any content, as the access log shows

[30/Dec/2015:16:47:07 -0500] "GET /znc/ HTTP/2.0" 200 1283 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:08 -0500] "GET /znc/pub/dark-clouds.css HTTP/2.0" 200 1868 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:08 -0500] "GET /znc/skinfiles/_default_/global.css HTTP/2.0" 200 382 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:08 -0500] "GET /znc/pub/jquery-ui-sortable.1.11.4.min.css HTTP/2.0" 200 3609 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:08 -0500] "GET /znc/pub/selectize-0.12.1.css HTTP/2.0" 200 2373 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:08 -0500] "GET /znc/pub/jquery-1.11.2.min.js HTTP/2.0" 200 96159 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:08 -0500] "GET /znc/pub/jquery-ui-sortable.1.11.4.min.js HTTP/2.0" 200 38165 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:09 -0500] "GET /znc/pub/selectize-standalone-0.12.1.min.js HTTP/2.0" 200 42551 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:47:09 -0500] "GET /znc/pub/clouds-header.jpg HTTP/2.0" 200 31228 "https://herp.derp/znc/pub/dark-clouds.css" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"

This is the setup.

server {
    listen                      443 ssl http2 default_server;
    listen                      [::]:443 ssl http2 default_server;
    server_name                 herp.derp;
    index                       index.html;
    root                        /home/derp/www/;
    access_log                  /var/log/nginx/access.log;

    # ZNC webadmin
    location /znc/ {
        proxy_set_header        X-Forwarded-For proxy_add_x_forwarded_for;
        proxy_pass              http://[::1]:7777;
    }
}

But if I try to cache static content on my website, everything except static content on https://herp.derp/znc/ works.

This is the setup

server {
    listen                      443 ssl http2 default_server;
    listen                      [::]:443 ssl http2 default_server;
    server_name                 herp.derp;
    index                       index.html;
    root                        /home/derp/www/;
    access_log                  /var/log/nginx/access.log;

    # ZNC webadmin
    location /znc/ {
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass              http://[::1]:7777;
    }

    # Client Caching
    location ~* \.(?:jpg|jpeg|png|gif|ico|css|js|ttf)$ {
        expires                 1y;
        add_header              Cache-Control public;
    }
}

And these are the exact same files as above now throwing 404s

[30/Dec/2015:16:35:31 -0500] "GET /znc/ HTTP/2.0" 200 1283 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"  
[30/Dec/2015:16:35:31 -0500] "GET /znc/pub/dark-clouds.css HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"  
[30/Dec/2015:16:35:31 -0500] "GET /znc/skinfiles/_default_/global.css HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"  
[30/Dec/2015:16:35:32 -0500] "GET /znc/pub/jquery-ui-sortable.1.11.4.min.css HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"  
[30/Dec/2015:16:35:32 -0500] "GET /znc/pub/selectize-0.12.1.css HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"  
[30/Dec/2015:16:35:32 -0500] "GET /znc/pub/jquery-1.11.2.min.js HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:35:32 -0500] "GET /znc/pub/jquery-ui-sortable.1.11.4.min.js HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:35:32 -0500] "GET /znc/pub/selectize-standalone-0.12.1.min.js HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"
[30/Dec/2015:16:35:32 -0500] "GET /znc/favicon.ico HTTP/2.0" 404 640 "https://herp.derp/znc/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"

What am I doing wrong? And how do I accomplish what I want to do?

Upvotes: 0

Views: 1747

Answers (2)

E1NSER
E1NSER

Reputation: 21

Putting the Cache-Block inside and outside the “location /“ worked perfectly 👍🏻. After hours of investigation this was the only working solution for Nuxt in combination with Nginx.

Upvotes: 0

txtsd
txtsd

Reputation: 181

I managed to solve my problem by replicating the regex location block inside the /znc/ location block, and passing it the same proxy directives. Apparently nginx only matches one location block per request.

server {
    listen                      443 ssl http2 default_server;
    listen                      [::]:443 ssl http2 default_server;
    server_name                 herp.derp;
    index                       index.html;
    root                        /home/derp/www/;
    access_log                  /var/log/nginx/access.log;


    # ZNC webadmin
    location /znc/ {
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass              http://[::1]:7777;

        # Client Caching
        location ~* \.(?:jpg|jpeg|png|gif|ico|css|js|ttf)$ {
            expires             1y;
            add_header          Cache-Control public;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass          http://[::1]:7777;
        }
    }

    # Client Caching
    location ~* \.(?:jpg|jpeg|png|gif|ico|css|js|ttf)$ {
        expires                 1y;
        add_header              Cache-Control public;
    }
}

Upvotes: 1

Related Questions