Monday, May 25, 2015

setting HTTP Headers in apache httpd.conf

Sponsored Links
In a lot of cases, we have to set particular http headers for objects. For example to set the caching age, caching control etc. How the http headers can be set? This can be done very easily using the Apache web server configuration file.


Suppose you want to set http headers for the mp4 or mpd(MPEG Dash) video files served by the webserver.

Open the httpd.conf in your favourite editor and add the following.

<FilesMatch ".(mpd|mp4)">
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Allow-Headers "Origin,Content-Type,Access-Control-Allow-Origin,Range,Accept"

        Header set Access-Control-Expose-Headers "Access-Control-Allow-Origin, Content-Length, Content-Type, Date, Range, Server, Transfer-Encoding"
        Header set Access-Control-Allow-Methods "GET,POST,PUT,DELETE,OPTIONS"

        Header set Access-Control-Max-Age "1800"
</FilesMatch>

Restart or reload Apache.

Checking the response:
Response:
[root@localhost ~]# curl -I http://xxx.amazonaws.com/DARK_KNIGHT.mpd
HTTP/1.1 200 OK
Date: Wed, 20 May 2015 08:36:17 GMT
Server: Apache
Last-Modified: Mon, 04 May 2015 13:16:44 GMT
ETag: "682461-a5a-5f91c700"
Accept-Ranges: bytes
Content-Length: 2650
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Origin,Content-Type,Access-Control-Allow-Origin,Range,Accept
Access-Control-Expose-Headers: Access-Control-Allow-Origin, Content-Length, Content-Type, Date, Range, Server, Transfer-Encoding
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS
Access-Control-Max-Age: 1800
Connection: close
Content-Type: text/xml

Thats it. Have fun. Share the knowledge. 

Sponsored Links

No comments:

Post a Comment

Be nice. That's all.