How to Set Expires With Try Files

Joshua Pearce joshua.pearce at gmail.com
Fri May 20 05:54:41 MSD 2011


Below is my config file. How can I change the two "if" blocks to try_files, and still do a 30d expires for static files?

server {
        listen   80;
        server_name  www.joshpearce.org;
        client_max_body_size 4M;
        access_log  /var/log/nginx/localhost.access.log;

        # root of website *exactly*, use '=' for speed
        location = / {
                root /var/www/joshpearce.org;
                index index.php index.html index.htm;
        }
        location / {
                root   /var/www/joshpearce.org;
                index index.php index.html index.htm;
                if (-f $request_filename) {
                        expires 30d;
                        break;
                }
                if (!-e $request_filename) {
                        rewrite ^(.+)$ /index.php?q=$1 last;
                }
        }
        # use: htpasswd - htpwds NewUser NewPassword
        location ^~ /info {
                auth_basic  "Restricted";
                auth_basic_user_file /etc/nginx/htpwds;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass  unix:/usr/local/var/run/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www/joshpearce.org$fastcgi_script_name;
        }
        location ~ \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass  unix:/usr/local/var/run/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www/joshpearce.org$fastcgi_script_name;
        }

        #error_page  404  /404.html;
}



More information about the nginx mailing list