NGINX-缓存静态(CSS / JS)文件后出现404错误

时间:2019-05-01 20:15:13

标签: nginx caching http-status-code-404 cache-control

我正在尝试设置nginx来缓存我的静态文件,例如jpg,jpeg,css和js。

以下是我的nginx.conf(不是nginx.conf.default)的样子

events {}
http {

 server {
    listen       3000;
    # listen       443 ssl;
    server_name  localhost;
    # Set the SSL header only for HTTPS requests.
    if ($scheme = "https") {
        set $ssl_header SSL;
    }
    error_page 401 = @error401;
    client_max_body_size 1000M;

    # Expire rules for static content
    location / {
        # HTTPS header.
        proxy_set_header        X-Proto $ssl_header;
        proxy_set_header        Host $host;
        proxy_set_header        Client-IP $remote_addr;

        # Redirection host.
        proxy_pass              http://localhost:300x;

     }

      location ~* .(jpg|jpeg|css|js)$ {
         expires 1d;
         access_log off;
         add_header Cache-Control "public";
      }

然后我尝试将以下内容添加到缓存:

        location ~* .(jpg|jpeg|css|js)$ {
        expires 1d;
        access_log off;
        add_header Cache-Control "public";
        }

我的所有CSS和JS文件都收到404错误。我的JPG和JPEG文件被缓存。我已经厌倦了在这里添加根目录以及in位置\ {}块。这似乎没有什么不同。

我尝试了许多不同的配置-我只想知道如何缓存我的CSS和JS文件!

供参考:这是我的nginx.conf.default文件中的位置块:

        location / {
        root   html;
        index  index.html index.htm;
        }

我尝试在服务器块中添加根,没有运气

0 个答案:

没有答案
相关问题