2

I have an nginx server that is showing a 200 response in my browser for requests like

https://server.com/app/static/js/2.8cc049f3.chunk.js

and showing a 304 on the server logs

"GET /static/js/2.8cc049f3.chunk.js HTTP/1.1" 304 0 "https://server.com/app"

There is another nginx in front of the nginx running on server.com that is removing the app from the path. Based on the nginx logs on server.com this is working correctly. The static folder is in my root /usr/share/nginx/html/.

The content my browser receives for the js file is the index.html. However when I login to the server and run

curl http://localhost/static/js/2.8cc049f3.chunk.js

I get the correct js content in response and in the logs the server prints 200

"GET /static/js/2.8cc049f3.chunk.js HTTP/1.1" 200 1570391 "-" "curl/7.80.0" "-"

Here is my nginx.conf

server {
    listen  80;
    root    /usr/share/nginx/html/;
    index   index.html;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~ ^/(static)/  {
        gzip_static on;
        gzip_types
            text/plain
            text/xml
            text/css
            text/comma-separated-values
            text/javascript application/x-javascript
            application/atom+xml;
        expires max;
    }
}

I've read that a 304 means the file hasn't changed and tells your browser to use its local cache, so I cleared my browser cache. I also restarted nginx, thinking that the first request would give a 200 response on the server but it was still a 304.

Based on the local curl request being successful I don't think there is anything wrong with my nginx.conf. I don't know if nginx somehow has the index.html cached as the content of my js, or if I didn't clear my browser cache correctly.

I'm also confused why the response code is 304 on the server but 200 in my browser.

1
  • 1
    This isn't related to your question, but why do you use regex location ~ ^/(static)/ { ... } instead of prefix location /static/ { ... }? Being an equal in functionality, the second one will be more performant. Commented Feb 11, 2022 at 0:26

1 Answer 1

3

The HTTP 304 says "Not-Modified". This is because you are using another NGINX Proxy server in front of the NGINX Server we are talking about.

The 1st NGINX is requesting a resource on the 2nd NGINX and this one answers "Hey that file was not modified since the last time you have asked".

In this case it would be very helpful to check the configuration of the 1st NGINX Proxy instance or your turn of the caching in the first one and proxy_cache off; and check the result.

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.