title: Nginx Caching 404
body: <p>I am using WordPress with Nginx but whenever I try to enable caching of static files they turn to 404 not found.</p>
  
  <p>This is my <code>/etc/nginx/conf.d/default.conf</code> file:</p>
  
  <pre><code>server {
      listen   80;
      server_name  _;
  
  # SSL configuration
  listen 443 ssl default_server;
  ssl_certificate /etc/letsencrypt/live/shivampaw.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/shivampaw.com/privkey.pem;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
  ssl_dhparam /etc/nginx/ssl/dhparams.pem;
  ssl_session_timeout 30m;
  ssl_session_cache shared:SSL:10m;
  ssl_buffer_size 8k;
  add_header Strict-Transport-Security max-age=31536000;
  
      location / {
          root   /home/shivam/sites/shivampaw.com;
          index index.php  index.html index.htm;
          try_files $uri $uri/ /index.php?$args;
       }
  
      error_page  404              /404.html;
      location = /404.html {
          root   /usr/share/nginx/html;
      }
  
      # redirect server error pages to the static page /50x.html
      #
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   /usr/share/nginx/html;
      }
  
      # proxy the PHP scripts to Apache listening on 127.0.0.1:80
      #
      #location ~ \.php$ {
      #    proxy_pass   http://127.0.0.1;
      #}
  
      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      location ~ \.php$ {
          root           /home/shivam/sites/shivampaw.com;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
      }
  
      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      #location ~ /\.ht {
      #    deny  all;
      #}
  
  gzip on;
  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 9;
  gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_types text/plain text/css application/json applicationx-javascript text/xml application/xml application/xml+rss text/javascript;
  
  include wordpress/wordpress.conf;
  </code></pre>
  
  <p>And this is the WordPress.conf file:</p>
  
  <pre><code>location = /favicon.ico {
          log_not_found off;
          access_log off;
  }
  
  location = /robots.txt {
          allow all;
          log_not_found off;
          access_log off;
  }
  
  # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
  # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
  location ~ /\. {
          deny all;
  }
  
  # Deny access to any files with a .php extension in the uploads directory
  # Works in sub-directory installs and also in multisite network
  # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
  location ~* /(?:uploads|files)/.*\.php$ {
          deny all;
  }
  
  
  # Add trailing slash to */wp-admin requests.
  rewrite /wp-admin$ $scheme://$host$uri/ permanent;
  </code></pre>
  
  <p>With that, it works fine. But if I add </p>
  
  <pre><code># Media: images, icons, video, audio, HTC
  location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
  }
  
  # CSS and Javascript
  location ~* \.(?:css|js)$ {
    expires 1y;
    access_log off;
    add_header Cache-Control "public";
  }
  </code></pre>
  
  <p>To the end of wordpress.conf and restart nginx and reload my site all the static files come up with 404.</p>
  
  <p>So I have to comment that caching out and it works fine.</p>
  
  <p>Any ideas?</p>
  
  <p><a href="https://i.stack.imgur.com/nuy2Z.png" rel="nofollow"><img src="https://i.stack.imgur.com/nuy2Z.png" alt="404s"></a>
  <a href="https://i.stack.imgur.com/BjZK3.png" rel="nofollow"><img src="https://i.stack.imgur.com/BjZK3.png" alt="Single 404"></a></p>
  
  <p>This means that if I include wp-rocket.conf (I use it) it also gives a 404 because wp-rocket.conf has caching stuff in it.</p>
  
  <p>So basically, why can't i cache static files?</p>