1

I am running a Java webservice (JAX-WS) on Tomcat 8 from my AWS EC2 Linux instance, and I have a subdomain pointing to the service, so that I can call the service with URL http://services.example.com/api/myService1. This is the VirtualHost config:

<VirtualHost *:80>
    ServerName services.example.com
    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/Services/
    ProxyPassReverse / http://localhost:8080/Services/
</VirtualHost>

Now I would like to access some static files (images) stored in the server. Where should I store them and how should I access them?

I tried storing them on /opt/tomcat/webapps/ROOT/example.jpg and calling them as http://services.example.com/example.jpg but it doesn't work.

0

1 Answer 1

2

Create a new directory for example /opt/static/ and chown it to www-data or the equivalent on your OS and put your static stuff in there. This will totally bypass tomcat for the static assets (a good thing IMO)

and then change your vhost definition to this (I am assuming that all your api calls are in the api url - it will also enable client side caching for the static files.)

<VirtualHost *:80>
    ServerName services.example.com
    DocumentRoot /opt/static/

    #Cache static files for 1 month
    <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>

    <Location "/api/">
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>
        ProxyPass http://localhost:8080/Services/api
        ProxyPassReverse http://localhost:8080/Services/api
    </Location>
</VirtualHost>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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