2016-04-22 70 views
0

我在AWS上有ubuntu 14 ngnix指向一个网站。我尝试了一切,但它不提供静态图像。当我尝试缓存它们时。我已经厌倦了每一次这样的组合,但是每次去那里都没有文件。NGINX不缓存或保存静态文件

location ~* \.(css|js|jpeg|jpg|gif|png|ico|xml)$ { 
    access_log off; 
    expires 30d; 
} 

当我转到目录时,根路径中没有文件。有任何想法吗?

+0

显示完整的服务器块 –

+0

上游项目{ 服务器172.21.2.230;服务器{ }听80; location/{ proxy_pass http:// project; } location〜*。(css | js | gif | jpe?g | png)$ { expires 16h; } } – Matt

回答

0

这里是一个正式的块利用率https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/#

server { 
    # Replace this port with the right one for your requirements 
    listen 80 default_server; #could also be 1.2.3.4:80 

    # Multiple hostnames separated by spaces. Replace these as well. 
    server_name star.yourdomain.com *.yourdomain.com; # Alternately: _ 

    root /PATH/TO/WEBROOT; 

    error_page 404 errors/404.html; 
    access_log logs/star.yourdomain.com.access.log; 

    index index.php index.html index.htm; 

    # static file 404's aren't logged and expires header is set to maximum age 
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { 
    access_log off; 
    expires max; 
    } 

    location ~ \.php$ { 
    include fastcgi_params; 
    fastcgi_intercept_errors on; 
    # By all means use a different server for the fcgi processes if you need to 
    fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE; 
    } 

    location ~ /\.ht { 
    deny all; 
    }