skip to Main Content

I have backend API which like this :

http://192.168.65.203:2022/page/index.jsp

and i have Apache httpd server as a 1st layer before hit backend. I set the port as 8090.

Now i want for image file will only get from httpd server, not from backend server. So my VirtualHost look like this :

<VirtualHost *:8090>
ProxyPreserveHost On
ProxyRequests off
<Directory "/usr/share/myfile">
    Options Indexes FollowSymLinks
    AllowOverride None
    order allow,deny
    Allow from all
    Require all granted
</Directory>
AliasMatch ^/(.*.gif|.*.jpg|.*.jpeg|.*.png|.*.css|.*.swf)$ /usr/share/myfile/$1
ProxyPass / http://192.168.65.203:2022/
ProxyPassReverse / http://192.168.65.203:2022/

Problem : image still pickup from backend server. If i disable proxypass and proxypassreserve, it working fine (image can load from httpd server).

Expectation : how i can control if image is found (at alias rule) it should not go for proxypass? or is there any other method?

2

Answers


  1. Chosen as BEST ANSWER

    Directive ! is needed. Below is the solution for my problem..

    <VirtualHost *:8090>
    ProxyPreserveHost On
    ProxyRequests off
    <Directory "/usr/share/myfile">
        Options Indexes FollowSymLinks
        AllowOverride None
        order allow,deny
        Allow from all
        Require all granted
    </Directory>
    DocumentRoot "/usr/share/myfile"
    ProxyPassMatch ^/(.*.gif|.*.jpg|.*.jpeg|.*.png|.*.css|.*.swf)$ !
    ProxyPass / http://192.168.65.203:2022/
    ProxyPassReverse / http://192.168.65.203:2022/
    </VirtualHost>
    

    When the request is image type it will go to local file system "/usr/share/myfile" and the Directive ! is like to stop the proxy. Check here for more details for this directive.


  2. Replace [1] by [2] and try:

    [1] : 
    AliasMatch ^/(.*.gif|.*.jpg|.*.jpeg|.*.png|.*.css|.*.swf)$ /usr/share/myfile/$1
    
    [2] :
    ProxyPassMatch ^/(*.gif)$   !
    ProxyPassMatch ^/(*.jpg)$   !
    ProxyPassMatch ^/(*.jpeg)$  !
    ProxyPassMatch ^/(*.png)$   !
    ProxyPassMatch ^/(*.css)$   !
    ProxyPassMatch ^/(*.swf)$   !
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search