How to serve static content from Apache Web Server?
Environment
- Red Hat JBoss Enterprise Web Server (EWS) 1.x,2.x
- Apache httpd 2.2.x
- Apache httpd 2.4.x
Issue
- How can we include static content from external shared folders in EWS/Apache httpd? Any requests to these resources should be excluded from mod_jk AJP. Currently these contents are being deployed as part of our EAP(with entries in profile.xml and vfs.xml), which in fact, is not required. This causes lot of time being spent in deployment.
- How to use
Alias
to server static files from Apache httpd?
Resolution
-
A simple test case would be as follows:
- For Apache 2.2.x
- Create images in the
/var/www/img
directory - In
httpd.conf
, have the following configuration.
<VirtualHost *:80>
ServerName myapp.example.com
DocumentRoot /var/www/
Alias /images "/var/www/img/"
<Directory "/var/www/img">
Options +Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
- Go to url http://localhost/images and you should see the images listed.To prevent directory listings remove Options +Indexes.
-
For more details check Apache httpd 2.2 mod_alias module documentation
- For Apache httpd 2.4.x:
Order deny,allow
Allow from all
The above directives used in 2.2.x have been replaced by below directive in 2.4.x.
Require all granted
Hence, the configuration will be like below:
<VirtualHost *:80>
ServerName myapp.example.com
DocumentRoot /var/www/
Alias /images "/var/www/img/"
<Directory "/var/www/img">
Options +Indexes
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments