1

I have a working configuration in nginx which is like this

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_redirect default;

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

        client_max_body_size       100m;
        client_body_buffer_size    128k;

        proxy_connect_timeout      600;
        proxy_send_timeout         600;
        proxy_read_timeout         600;

        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
    }

    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|htm|html)$ {
        root PATH_TO_STATIC_CONTENT;
    }

}

How can I emulate this with apache ? I tried the below configuration but the static content do not serve.

<VirtualHost *:80>
ServerName example.com
DocumentRoot PATH_TO_STATIC CONTENT
<Location />
  ProxyPass http://127.0.0.1:8000
</Location>
<LocationMatch SAME_REGEXP_AS_NGINX>
    ProxyPass !
</LocationMatch>
</VirtualHost>

How can I get static content to serve in the same way as nginx does? Or is it even possible ? Thanks in advance

sagarchalise
  • 111
  • 2

1 Answers1

1

The order of ProxyPass directives matters, and unlike nginx, all location blocks that are match are applied, from least specific to most specific.

In other words, you'll need to change your approach a bit for it to work.

Probably the more straightforward and readable approach would be to use mod_rewrite:

RewriteRule \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|htm|html)$ - [L]
RewriteRule ^/(.*)$ http://127.0.0.1:8000/$1 [P,L]
Shane Madden
  • 114,520
  • 13
  • 181
  • 251