0

My config for my Angular 6 app:

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

    try_files $uri $uri/ /index.html;
    expires       0;
    add_header    Cache-Control  private;
    add_header    Cache-Control  must-revalidate;

    location / {
        add_header    Cache-Control  no-store;
        add_header    Cache-Control  no-cache;
    }

    location /assets/fonts {
    }
}

When I push F5 I get "404 Not Found"

If I change config to:

server {
    listen 80 default_server;
    root /usr/share/nginx/html;
    index index.html;
    server_name localhost;
    location / {
        try_files $uri $uri/ /index.html?$args;
        expires       0;
        add_header    Cache-Control  private;
        add_header    Cache-Control  no-store;
        add_header    Cache-Control  no-cache;
        add_header    Cache-Control  must-revalidate;
    }
}

My page reloads successfully.

But I need to configure the cache settings for /assets/fonts. How to fix it?

Thank you.

2
  • What if you add location /assets/fonts{... to the second config? Commented Jan 16, 2020 at 14:50
  • David, it's work, but why? Post you answer, I check it as right answer. New config: location / { try_files $uri $uri/ /index.html?$args; expires 0; add_header Cache-Control private; add_header Cache-Control no-store; add_header Cache-Control no-cache; add_header Cache-Control must-revalidate; } location /assets/fonts { try_files $uri $uri/ /index.html?$args; expires 0; add_header Cache-Control private; add_header Cache-Control must-revalidate; } Commented Jan 16, 2020 at 15:09

1 Answer 1

1

Your first config did not work because the location block was used, which contained no rule.

To achieve what you want, it could work like this without having to add a 2nd try in the /assets/fonts location

server {
    listen 80 default_server;
    root /usr/share/nginx/html;
    index index.html;
    server_name localhost;
    location / {
        try_files $uri $uri/ /index.html?$args;
        expires       0;
        add_header    Cache-Control  private;
        add_header    Cache-Control  no-store;
        add_header    Cache-Control  no-cache;
        add_header    Cache-Control  must-revalidate;
    }

    location /assets/fonts {

     root /usr/share/nginx/html; #instead of using try_file
     #Add your headers here
    }
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.