2

We have NGinX as proxy server for PHP web application. PHP scripts are served by PHP-FPM process. Following is the configuration for the nginx:

location /app/ {
    alias /var/www/html;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|svg|ttf|woff)$ {
        alias /var/www/html;
        expires 24h;
        log_not_found on;
        try_files $uri $uri;
    }
    rewrite /app.* /app/index.php?$args;

    location ~ \.php$ {
        try_files $uri =404;

        # typical php-fpm configuration
    }
}
# wordpress site hosted on root of the domain
location / {
    try_files $uri $uri/ /index.php?$args;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|svg|ttf|woff)$ {
    expires 24h;
    log_not_found off;
    auth_basic off;
}

PHP application itself is Yii based. Now issue is that when NGinx is serving a static image, it is truncating the actual path randomly (sometimes after 80 characters or sometimes after 4 dash in the url). e.g.

Lets say URL accessed is example.com/app/themes/app/images/some_folder/some_image_name.png, it is showing 404 and in error.log I am seeing that NGinx is trying to locate following path /var/www/html/app/themes/app/images/some_folder/**some_image_name.pn/** (g is removed from URL) while another image, whose file name is shorter than culprit one, at same location is being located successfully.

EDIT: We have noted a pattern, actually nginx is appending the $uri again after the original $uri i.e in above mentioned example it replace 'g' with '/' which is the starting character of the $uri and in another case it replace '.png' with '/var'. Hope it helps in debugging. :)

2
  • I see nothing in your configuration that might do this. I would first suspect your application. Jan 29, 2014 at 6:56
  • It works fine if I move the nested location configuration (i.e. ~* \.php location inside /app) out of /app location but in that case my php application does not work.
    – vikas
    Jan 29, 2014 at 7:01

1 Answer 1

0

Changing alias to root for directory path would solve your problem.

location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|svg|ttf|woff)$ {
    root /var/www/html;
    expires 24h;
    log_not_found on;
    try_files $uri $uri;
}
1
  • It worked like a charm. So trivial but difficulat to locate fix. :)
    – vikas
    Jan 30, 2014 at 7:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .