我在我的AWS EC2 Linux实例上运行Tomcat 8上的Java webservice(JAX-WS),并且我有一个指向该服务的子域,以便我可以使用URL http://services.example.com/api/myService1调用服务http://services.example.com/api/myService1 。 这是VirtualHostconfiguration:
<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>
现在我想访问存储在服务器中的一些静态文件(图像)。 我应该在哪里存储它们,我应该如何访问它们?
我尝试将它们存储在/opt/tomcat/webapps/ROOT/example.jpg ,并将它们作为http://services.example.com/example.jpg调用,但它不起作用。
创build一个新的目录,例如/opt/static/并将其chown为www-data或等效的操作系统,并将静态内容放在那里。 这将完全绕过Tomcat的静态资产(一个好事IMO)
然后改变你的虚拟主机定义(我假设你的所有api调用都在apiurl – 它也将启用客户端caching的静态文件。)
<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>