Nginx expire directive

Discussion in 'Server Operation' started by Blaasbalg, Nov 23, 2015.

  1. Blaasbalg

    Blaasbalg Member

    Edit: disregard, while continuing my search for the cause of the issue I cleared my browser cache just to be absolutely sure that wasn't it (I was constantly using Ctrl + F5 during the initial troubleshooting, but apparently that wasn't enough)... and it solved the issue. So it was probably working the entire time... I feel so incredibly silly right now
    -----------------------------------

    Hello,

    I'm currently trying to get Nginx to add expiration headers to all css/js/image files using the expire directive. This seems rather trivial at first, however, no matter what I try, it simply refuses to add the headers to any of the files to which it should add them, as per the location directive.

    Here's the main part of the configuration file (irrelevant directives are stripped out):

    Code:
    server {
            location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location /stats/ {
    
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /<*>/web1/web/stats/.htpasswd_stats;
            }
    
            location ^~ /awstats-icon {
                alias /usr/share/awstats/icon;
            }
    
            location ~ \.php$ {
                try_files /5e4c1d668baee6ccd0318369ea968059.htm @php;
            }
    
            location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    
            if ($scheme = http) {
              return 301 https://$server_name$request_uri;
            }
    # -----
            location ~* \.(?:jpg|jpeg|png|gif|ico|css|js)$ {
              expires 14d;
            }
    # -----
            location / {
              error_page 400 401 402 403 404 500 502 503 504 /error/errorhandler.php?http=$status;
            }
    
            location /dev/ {
              try_files $uri $uri/ /dev/index.php?$args;
            }
    
            location ^~ /dev/uploads/ {
    
            }
    }
    The part where I'm trying to add the expire headers:
    Code:
            location ~* \.(?:jpg|jpeg|png|gif|ico|css|js)$ {
              expires 14d;
            }
    What am I missing here?
     
    Last edited: Nov 23, 2015

Share This Page