首页 > 解决方案 > nginx缓存静态文件,接受的答案对我不起作用

问题描述

NGINX 缓存静态文件

我在我的 nginx 中有这个配置,我仍然得到 OP 的结果。

还有其他需要考虑的吗?我只是告诉浏览器缓存静态文件正确吗?Nginx 没有缓存它,这是我的假设,但是一旦我把那个位置指令放进去,这就是我为所有匹配的东西得到的错误。它似乎正在服务器上本地查找文件。但是,我将其删除,它可以正常工作并从代理服务器提供服务。

错误:

"/etc/nginx/html/static/js/scripts.js" failed (2: No such file or directory)

配置:

worker_processes auto;
worker_rlimit_nofile 8192;

events {
  worker_connections  4096;  ## Default: 1024
  
}

http {
  include    /etc/nginx/mime.types;
  include    /etc/nginx/proxy.conf;

  index    index.html;

  default_type application/octet-stream;
  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
  # access_log   logs/access.log  main;
  sendfile     on;
  tcp_nopush   on;
  server_names_hash_bucket_size 128; # this seems to be required for some vhosts
  ssl_session_cache   shared:SSL:10m;
  ssl_session_timeout 10m;

  server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
  }


  server { 
    listen  443 ssl;
    server_name  domaincom;
    ssl_certificate     /etc/nginx/cert.pem;
    ssl_certificate_key /etc/nginx/key.pem;
    keepalive_timeout   70;

    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
      expires 1M;
      # access_log off;
      add_header Cache-Control "public";
      add_header Vary Accept-Encoding;
    }

    # pass requests for dynamic content to rails/turbogears/zope, et al
    location / {
      proxy_pass      http://ssapp:5000;
    }
  }


}

标签: nginx

解决方案


推荐阅读