Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6998627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:26:07+00:00 2026-05-27T20:26:07+00:00

I’ve been using a vanilla apache install until recently with no major problems. Today

  • 0

I’ve been using a vanilla apache install until recently with no major problems.

Today I installed Nginx Admin (the cpanel nginx plugin) which acts as a reverse proxy for Apache to deliver static files.

This all works very well and there is a noticable performance boost which I am pleased with.

However my site hosts a large amount of MP3 files which prior to using Nginx would all get cached by the browser meaning that a user only had to download them once and subsequent listens were instananeous.

Now, with Nginx Admin installed the browser requests the file from the server every time.

I have tried adding the following to my nginx config file:-

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

But even this had no effect. What might be causing this and what else can I try to rectify this issue?

Strangely under apache my header looks like this:-

  Server    Apache
Connection  Keep-Alive
Keep-Alive  timeout=5, max=98
Vary    Accept-Encoding,User-Agent

This returns a 304 Not Modified response after being cached

and with nginx admin installed the headers are as follows:-

Server  nginx admin
Date    Thu, 24 Nov 2011 12:46:27 GMT
Content-Type    audio/mpeg
Content-Length  5263187
Last-Modified   Mon, 26 Sep 2011 18:29:39 GMT
Connection  keep-alive
Expires Thu, 01 Dec 2011 12:46:27 GMT
Cache-Control   max-age=604800
X-Cache HIT from Backend
Accept-Ranges   bytes

Which no matter what always returns a 200 OK.

My nginx config file is as follows:-

user  nobody;
# no need for more workers in the proxy mode
worker_processes  4;
error_log  /var/log/nginx/error.log info;
worker_rlimit_nofile 20480;
events {
 worker_connections 5120; # increase for busier servers
 use epoll; # you should use epoll here for Linux kernels 2.6.x
}
http {
 server_name_in_redirect off;
 server_names_hash_max_size 10240;
 server_names_hash_bucket_size 1024;
 include    mime.types;
 default_type  application/octet-stream;
 server_tokens off;
 sendfile on;
 tcp_nopush on;
 tcp_nodelay on;
 keepalive_timeout  5;
 gzip on;
 gzip_vary on;
 gzip_disable "MSIE [1-6]\.";
 gzip_proxied any;
 gzip_http_version 1.1;
 gzip_min_length  1000;
 gzip_comp_level  6;
 gzip_buffers  16 8k;
# You can remove image/png image/x-icon image/gif image/jpeg if you have slow CPU
 gzip_types    text/plain text/xml text/css application/x-javascript application/xml image/png image/x-icon image/gif image/jpeg application/xml+rss text/javascript application/atom+xml;
 ignore_invalid_headers on;
 client_header_timeout  3m;
 client_body_timeout 3m;
 send_timeout     3m;
 reset_timedout_connection on;
 connection_pool_size  256;
 client_header_buffer_size 256k;
 large_client_header_buffers 4 256k;
 client_max_body_size 200M; 
 client_body_buffer_size 128k;
 request_pool_size  32k;
 output_buffers   4 32k;
 postpone_output  1460;
 proxy_temp_path  /tmp/nginx_proxy/;
 client_body_in_file_only on;
 log_format bytes_log "$msec $bytes_sent .";
 include "/etc/nginx/vhosts/*";
}

With this domain specific file being included:-

server {
          error_log /var/log/nginx/vhost-error_log warn;
          listen x.x.x.x:x;
          server_name songbanc.com www.songbanc.com;
          access_log /usr/local/apache/domlogs/mydomain.com-bytes_log bytes_log;
          access_log /usr/local/apache/domlogs/mydomain.com combined;
          root /home/mydomain/public_html;
          location / {
          location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
          expires 7d;
          try_files $uri @backend;
          }
          error_page 405 = @backend;
          add_header X-Cache "HIT from Backend";
          proxy_pass http://x.x.x.x:8081;
          include proxy.inc;
          }
          location @backend {
          internal;
          proxy_pass http://x.x.x.x:8081;
          include proxy.inc;
          }
          location ~ .*\.(php|jsp|cgi|pl|py)?$ {
          proxy_pass http://x.x.x.x:8081;
          include proxy.inc;
          }
          location ~ /\.ht {
          deny all;
          }

          location ~* \.(mp3)$ {
          expires max;
          }             
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:26:07+00:00Added an answer on May 27, 2026 at 8:26 pm

    I believe the reason may be because your conf file was unnecessarily complex and errors start to creep into such configs.

    location ~ .*\.(php|jsp|cgi|pl|py)?$ should be location ~ .*\.(php|jsp|cgi|pl|py)$.

    The long nested if block under location / is similarly not required.

    The add_header X-Cache directive should be in proxy.inc.

    Named locations such as “@backend” do not need “internal” directives.

    Anyway, after striping things down, we are left with:

    server {
        error_log /var/log/nginx/vhost-error_log warn;
        listen x.x.x.x:x;
        server_name songbanc.com www.songbanc.com;
        access_log /usr/local/apache/domlogs/mydomain.com-bytes_log bytes_log;
        access_log /usr/local/apache/domlogs/mydomain.com combined;
        root /home/mydomain/public_html;
        index index.html index.php;
        error_page 418 = @backend;
    
        location / {
            expires 7d;
            add_header Cache-Control "public";
            try_files $uri $uri/ @backend;
        }
        location ~* \.mp3$ {
            # Add rewrite rules to handle these requests here
            add_header Cache-Control "public";
            expires max;
        }
        location ~ .*\.(php|jsp|cgi|pl|py)$ {
            return 418;
        }
        location @backend {
            proxy_pass http://x.x.x.x:8081;
            include proxy.inc;
        }
        location ~ /\.ht {
            deny all;
        }
    }
    

    This should have the static files cached and dynamic ones not cached. requires rewrite rules for the mp3 block to be translated from the backend.

    Alternatively, you can just pass the mp3 requests to the backend.

    server {
        error_log /var/log/nginx/vhost-error_log warn;
        listen x.x.x.x:x;
        server_name songbanc.com www.songbanc.com;
        access_log /usr/local/apache/domlogs/mydomain.com-bytes_log bytes_log;
        access_log /usr/local/apache/domlogs/mydomain.com combined;
        root /home/mydomain/public_html;
        index index.html index.php;
        error_page 418 = @backend;
    
        location / {
            expires 7d;
            add_header Cache-Control "public";
            try_files $uri $uri/ @backend;
        }
        location ~* \.mp3$ {
            add_header Cache-Control "public";
            expires max;
            return 418;
        }
        location ~ .*\.(php|jsp|cgi|pl|py)$ {
            return 418;
        }
        location @backend {
            proxy_pass http://x.x.x.x:8081;
            include proxy.inc;
        }
        location ~ /\.ht {
            deny all;
        }
    }
    

    I am not 100% certain if directives such as “expires” and “add_header” are not cleared when a redirect is triggered. If you find that you are not getting the you headers with the config above, this slightly longer one should do it.

    server {
        error_log /var/log/nginx/vhost-error_log warn;
        listen x.x.x.x:x;
        server_name songbanc.com www.songbanc.com;
        access_log /usr/local/apache/domlogs/mydomain.com-bytes_log bytes_log;
        access_log /usr/local/apache/domlogs/mydomain.com combined;
        root /home/mydomain/public_html;
        index index.html index.php;
        error_page 418 = @backend;
    
        location / {
            expires 7d;
            add_header Cache-Control "public";
            try_files $uri $uri/ @backend;
        }
        location ~* \.mp3$ {
            error_page 418 = @backend_alt;
            return 418;
        }
        location ~ .*\.(php|jsp|cgi|pl|py)$ {
            return 418;
        }
        location @backend {
            proxy_pass http://x.x.x.x:8081;
            include proxy.inc;
        }
        location @backend_alt {
            proxy_pass http://x.x.x.x:8081;
            include proxy.inc;
            add_header Cache-Control "public";
            expires max;
        }
        location ~ /\.ht {
            deny all;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.