h5bp/server-configs

[nginx] nginx/conf/expires.conf breaks rewrite rules

pocesar opened this issue · 8 comments

If I include the file expires.conf in my site configuration, this rewrite:

    rewrite "([a-z0-9]{32})\.png" /index.php?page=log&id=$1 last;

stops working, and gives a 404. The error started happening on my site after I included the expires.conf (because I moved from apache to nginx recently) and it used to work on Apache, so I decided to use it on nginx as well... any idea on how to fix this issue (while still keeping expires.conf of course)

Please show the equivalent of this file

9mm commented

It also breaks for me. (breaks images, html, everything)

9mm commented

EC2, behind elastic load balancer

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /var/www/html/example.com;
        index  index.html index.htm;
    }

    # Specify a charset
    charset utf-8;

    # Custom 404 page
    error_page 404 /404.html;

    include conf/base.conf;
}
9mm commented

The problem was I changed my nginx root path from /usr/share/nginx or whatever it is by default to /var/www/html/site.com

That means the root command should have happened in my server directive instead of my location directive so that it trickles down. Because it couldnt see any root defined it was using the binary default

http://docs.ngx.cc/en/latest/topics/tutorials/config_pitfalls.html

my root is outside my location.

@AD7six I don't have my original file layout, because I stopped using it for breaking my rewrites...

@ecefx the file you've shown only includes another file that isn't shown. (From subsequent comments, I assume you found "the cause").

@pocesar without knowing the order the config files were included, It's not possible to point out the exact cause of what you've reported.

rewrite "([a-z0-9]{32}).png"

This would obviously need to be before the block which applies expires rules - otherwise only the expire rules config would apply.

Closing as works-for-me as no further information has been provided.