Nginx – Using nginx with apache as reverse proxy

apache-2.2centosnginxreverse-proxyweb-server

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,

Best Answer

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

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

Instead of :

location /admin/tools/phpmyadmin
Related Topic