views:

15

answers:

1

My website is a online music portal with online playing system.

When user play a song, it is served by nginx server on port 8080 on my server.

The problem is when the song has finished playing, the player repeats the song. But every time it replays, it makes another call to server and starts downloading the file again to play.

Previously i had apache to serve these files. At that time, user just requested file once and replays were played from his cache. How can i achieve this using nginx

[I am not using any script like php or so to serve the file. It's just direct link. Like http://www.myserver.com:8080/music/song1.mp3]

A: 

It would help a lot to see some of your former Apache configuration and current Nginx configuration to see how they're set up to put expiration headers on outbound files. This isn't a foolproof way to enforce caching, as you may know, but it sounds like "good enough" will work for you. Try an Nginx configuration block within your server{} block which reads like this:

location ~* \.(mp3)$ {
    expires max;
}

That should set a far-future expiration date on your files and encourage the browser to cache them longer.

pjmorse
Thanks bro pjmorse. That worked for me. :)
Hardeep