Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I was trying to get a static only config for nginx working with try_files but was running into some issues. The following is what I have working right now (but does not deal with directories, showing index etc.) I would like to see if I can get a version with try_files working...

  server {
    listen 80;
    server_name foo.com;
    rewrite ^ http://www.foo.com$uri permanent;
  }

  # the server directive is nginx's virtual host directive.
  server {
    # port to listen on. Can also be set to an IP:PORT
    listen 80;

    # Set the charset
    charset utf-8;

    # Set the max size for file uploads to 10Mb
    client_max_body_size 10M;

    # sets the domain[s] that this vhost server requests for
    server_name www.foo.com; 

    # doc root
    root /var/www/foo.com;

    # vhost specific access log
    access_log  /var/log/nginx_access.log  main;


    # Set image format types to expire in a very long time
    location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
        access_log off;
        expires max;
    }

    # Set css and js to expire in a very long time
    location ~* ^.+\.(css|js)$ {
        access_log off;
        expires max;
    }

    location /blog {
     rewrite ^ http://blog.foo.com permanent; 
    }

    # Catchall for everything else
    location / {
      root /var/www/foo.com;
      access_log off;

      index index.html index.shtml;
      expires 1d;

      #try_files $uri $uri/;

      if (-f $request_filename) {
        break;
      }
    }

    location ~* ^/(pkg|rpms)/ {
      autoindex on;
    }

    error_page 500 502 503 504 /500.html;
    error_page 404 /404.html;

  }
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

From http://wiki.nginx.org/NginxHttpMainModule#try_files:

In the event that no file is found, and internal redirect to the last parameter is invoked.

Without a URI at the end of the try_files, it won't work right.

share|improve this answer
    
Ah, that makes sense. I ended up putting a /404.html at the end of the try_files directive and it works. –  Jauder Ho Jul 28 '09 at 7:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.