Hey, Recently I decided to switch to nginx from apache, I'm still using apache as a reverse proxy to take care of all of my dynamic content. Having worked with apache for the past 2-3 years, I know how to handle most of the possible configuration, but with nginx it's a new world.

Problem is when I'm using third party web application such as phpmyadmin, the pictures won't load, generally I would use an Alias in apache but defining a location (the nginx's Alias) won't help.

nginx.conf

# primary server - proxypass
server {
    listen       80;
    server_name  domain.com www.domain.com;

    access_log  /var/www/domain/logs/access_log.nginx main;
    error_log /var/www/domain/logs/error_log.nginx warn;
    root        /var/www/domain/html/http;

    # proxy to Apache 2 and mod_python
    location / {
        proxy_pass         http://127.0.0.1:8080/;
        proxy_redirect     off;

        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_max_temp_file_size 0;

        client_max_body_size       10m;
        client_body_buffer_size    128k;

        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;

        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
 }
location /admin/tools/phpmyadmin {
        root /var/www/admin/phpmyadmin;


        }


        # Static files location
        location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
            root   /var/www/domain/html/http;
        }


}

The problem with the last Location bit is that it should take care of most of the static and never pass it throught apache (using apache only for a reverse proxy), but that also will redirect all pictures found on the /admin/tools/phpmyadmin Alias to the domain root.

Appreciate all help. Thanks,

link|improve this question

I was thinking to add a location (alias) with a regex such as: location ~ ^/admin/tools/phpmyadmin/.+.(jpg|jpeg|png|css|js)$ { root /var/www/admin/phpmyadmin; } – Adam Benayoun Sep 23 '09 at 13:59
Are you using fastcgi to handle php in the nginx server? or just trying to redirect the phpmyadmin location to apache? – HD. Sep 23 '09 at 14:50
I am redirecting the phpmyadmin to apache but would like to process the images via nginx – Adam Benayoun Sep 23 '09 at 15:56
feedback

2 Answers

If you're redirecting phpmyadmin to apache you need to use:

location ~ ^/admin/tools/phpmyadmin/(.+\.php)$

Instead of :

location /admin/tools/phpmyadmin
link|improve this answer
feedback

I'm guessing the first Location stanza is handling the request. Try moving the Location stanza for your static content above the root Location stanza. I can't remember if they are order specific, but I remember Apache is with it's VirtualHost declarations. Otherwise you could move the Location stanza for the static images into the root Location, and rewrite it as a test

if ( $request_url ~* /*.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$/ {
        root   /var/www/domain/html/http;
    }
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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