udexter
udexter

Reputation: 2347

Redirect problem with nginx (that works in Apache)

I've a problem with nginx configuration (that i get working with apache). I've to do a rewrite so I've configured:

    location = / {
            root   /var/www/domain.tld/public_html;
            index  index.php;
    }

    location / {
            root   /var/www/domain.tld/public_html;
            index  index.php;

            if (!-f $request_filename) {
                    rewrite  ^(.*)$  /index.php last;
                    break;
            }

            if (!-d $request_filename) {
                    rewrite  ^(.*)$  /index.php last;
                    break;
            }
    }


    # serve static files directly
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|wmv)$ {
            access_log        off;
            expires           30d;
    }

The problem is that I've static files located in dirs like /css, /img, /js but I also have a php controller that serves the user uploaded files and has the structure: domain.tld/media/image/NAME/EXTENSION. This doesn't works because it tries to get a static file, but If I go with domain.tld/media/image/NAME/EXTENSION/ (note the final /) it works.

How I can solve this?

Thank you in advance!

Upvotes: 1

Views: 904

Answers (1)

Adrien Clerc
Adrien Clerc

Reputation: 2797

You didn't read the documentation, did you? ;) It is listed in common pitfalls from users coming from Apache. Use the try_files directive, as described here: http://wiki.nginx.org/Pitfalls#Check_IF_File_Exists

Upvotes: 3

Related Questions