5

Here is the problem: I have a Linux server in Europe serving a busy Drupal site using nginx+php-fpm, I have another Linux server in the US (where a big portion of my visitors are coming from). The second server is heavily under-used. I am wondering how to make use of the second server to deliver my site's static content?

alfish
  • 3,027
  • 15
  • 45
  • 68

1 Answers1

4

Install Nginx on the 2nd server and set it up as a lightweight static proxy cache file server:

server {
 
        open_file_cache_valid 200 20m;
        listen 80;
        server_name yourcdndomain.com;
        access_log   /srv/www/yourcdndomain.com/logs/access.log;
        root   /srv/www/yourcdndomain.com/public_html/;
 
 
 
      location ~* \.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
                                # Cache static-looking files for 120 minutes, setting a 10 day expiry time in the HTTP header,
                                # whether logged in or not (may be too heavy-handed).
 
                                open_file_cache_valid 200 120m;
                        expires 7776000;
                        open_file_cache staticfilecache;
                }
 
location = /50x.html {
                root   /var/www/nginx-default;
        }
 
 # No access to .htaccess files.
        location ~ /\.ht {
          deny  all;
        }
 
    }

Rewrite your static files to the new domain or change the urls

Edit

I changed the file above to use open_file_cache instead of proxy_cache

Chris_O
  • 737
  • 4
  • 15
  • What is the point to `proxy_cache` static files you have already on the disk? Nginx serves them from `root` directory perfectly. – Alexander Azarov Apr 27 '11 at 11:13
  • @Alaz When you set `proxy_cache` Nginx will serve the files from shared memory even though it's not proxying back to another server. – Chris_O Apr 27 '11 at 18:06
  • @Chris_O Can you point to the documentation to prove this assertion? – Alexander Azarov Apr 27 '11 at 18:19
  • @Alaz I just looked over the new docs and [`open_file_cache`](http://wiki.nginx.org/HttpCoreModule#Directives) would be a better choice in this situation than [`proxy_cache`](http://wiki.nginx.org/HttpProxyModule) – Chris_O Apr 27 '11 at 20:37
  • Just to clarify. `proxy_cache` is a disk cache, not memory cache. It's zone (i.e. cache keys) reside in shared memory indeed, but the files are stored on disk and Nginx serves them just like any regular file. – Alexander Azarov Apr 28 '11 at 06:52
  • Regarding "open_file_cache". `open_file_cache` directive does not accept a "name", its arguments are `max=N [inactive=время]|off`. `open_file_cache_valid` accepts only one argument. – Alexander Azarov Apr 28 '11 at 06:54
  • This solution doesn't cover the need to send US-based requests for static content to the US server, and keep EU requests on the EU server. For that, the most straightforward way is to do geographic DNS load balancing, using a service such as DNS Made Easy (http://www.dnsmadeeasy.com/enterprisedns/trafficdirector.html). THere are many other similar services in this space. – rmalayter Apr 28 '11 at 12:59