1

I have following nginx config. if I remove the cache config for css everything works and all css files load perfectly via reverse proxy. but when I put in cache config for .css that results in 404 for all my css resources:

location ~* \.css {
          add_header Cache-Control public;
          add_header Pragma public;
          add_header Vary Accept-Encoding;
          expires 1M;
        } 

location / {
            proxy_pass http://localhost:8080;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header X-Forwarded-Proto $scheme;
             proxy_set_header X-Forwarded-Port $server_port;
        }

1 Answer 1

2

Nginx chooses a single location to process a request. That location needs to be complete. See how Nginx processes a request.

Your location ~* \.css block is missing the proxy_pass statement.

The proxy_set_header statements can be moved to the outer block and inherited by both location blocks.

For example:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;

location / {
    proxy_pass http://localhost:8080;
}

location ~* \.css {
    add_header Cache-Control public;
    add_header Pragma public;
    add_header Vary Accept-Encoding;
    expires 1M;

    proxy_pass http://localhost:8080;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.