Nginx as frontend of apache images style not generate when clean-url is on

Events happening in the community are now at Drupal community events on www.drupal.org.
hkvega01's picture

i'm trying to make a nginx as a proxy of apache, when the clean-url is on, i upload a image to a field, the thumbnails is not generated. I had read all of the thread around the google and tried every solutions but not work, here is my nginx vhost file

server {

 listen 80;
 server_name www.example.com example.com;
 access_log /var/log/virtualmin/example.com_nginx_access_log;
 error_log  /var/log/virtualmin/example.com_nginx_error_log;

 location / {

    index index.php;
proxy_pass http://192.168.1.104:8086;
    include /etc/nginx/proxy.conf;


 }

 location ~* \.(jpe?g|gif|png|ico|css|txt|php)$ {
    expires 30d;
    root /home/example/public_html;
 }

}

clean url on
http://www.example.com/sites/default/files/styles/thumbnail/public/10_2....
clean url off
http://www.example.com/?q=sites/default/files/styles/thumbnail/public/10...

Any ideas?

Comments

image is a 404 handler

perusio's picture

This is not going to work because you're telling nginx to serve all images without a 404 handler. You need tp define that your upstream is the 404 handler for the images managed by the image module.

I suggest you llok my configuration for an Apache upstream. Everything should workd out of the box. Now you have multiple options. It's easy to just enable the image handling with a much simpler config (untested).

root /home/example/public_html;

location / {
    try_files $uri @proxy;
}   

location @proxy {
    index index.php;
    proxy_pass http://192.168.1.104:8086;
    include /etc/nginx/proxy.conf;
}

## Just images handled by the image module.
location ~* /files/styles/.*\.(?:gif|jpe?g|png)$ {
      access_log off;
      expires 30d;
      try_files $uri @proxy;
}

## All other static files.
location ~* \.(?:jpe?g|gif|png|ico|css|txt)$ {
    expires 30d;
}

Note that you're opening a Pandora's box, regex based locations are matched based on the order in which they appear. Caveat emptor.

I changed my config

hkvega01's picture

I changed my config entirely

proxy_cache_path /home/d1/nginx/cache levels=1:2 keys_zone=STATIC:10m
inactive=24h max_size=1g;

server {
listen 123.123.123.123:80;
root /home/d1/public_html;
server_name d1.example.com;
access_log /var/log/virtualmin/d1.example.com_nginx_access_log;
error_log /var/log/virtualmin/d1.example.com_nginx_error_log;

location / {
    proxy_pass http://123.123.123.123:8081;
    include /etc/nginx/proxy.conf;
    proxy_cache     STATIC;
proxy_cache_valid   200 1d;
} 


#location ~ \.(jpe?g|png|js|css)$ {
    #proxy_pass http://123.123.123.123:8081;
    #include /etc/nginx/proxy.conf;
    #access_log off; 
    #expires 30d;
    #root /home/d1/public_html;

#}

#location ~* files/styles {
    #access_log off;
    #expires 30d;
    #try_files $uri @rewrite;
#}

#location @rewrite {
    #rewrite ^ /index.php last;
#}

}

the commented directive just make me some errors (e.g upload image not generate thumbnails/medium)

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: