NGINX as reverse proxy and cache of an external shared server running apache

4

I'm trying to set up a Brazilian instance on Amazon to be a reverse proxy with cache and compression for a server (I accept panel suggestions, preferably free, that accept this setting) in the US.

The goal is to use the maximum of Brazilian HD with nginx cache and maybe use it as NS to decrease the latency and time spent downloading the sites.

So we reduced hosting costs without losing performance.

In short: I want to cache using nginx from a server in the USA that runs apache2. All tutorials I found were related to running nginx and apache on the same machine and / or they worked only for one site, and manual configuration is required for each additional client.

    
asked by anonymous 22.02.2014 / 18:22

1 answer

2

Simply forward the requests made to your server by running Nginx and pass it to the external server, just as it would refer to a local apache. This is an example of configuration (it usually stays in /etc/nginx/conf.d/*.conf or /etc/nginx/sites-enabled/* ):

# definição do upstream: o servidor com apache que receberá as requisições
upstream apache {
    server xxx.xxx.xxx.xxx:80; 
    # Onde xxx.xxx.xxx.xxx é o endereço IP público do servidor remoto
}

# definição de onde você armazenará o cache (zona)
proxy_cache_path  /var/lib/nginx/cache levels=1:2 keys_zone=apachecache:180m  max_size=500m;

# limites de tempo
proxy_connect_timeout 30;
proxy_read_timeout 120;
proxy_send_timeout 120;

# condição e tempo de armazenamento do cache
proxy_cache_valid 200 60m;

# Configuração do servidor local
server {
    listen      80;
    server_name _;

    location / {
        # zona de cache: deve ser o mesmo nome que keys_zone
        proxy_cache apachecache;

        # Esta diretriz fará com que você possa utilizar as configurações 
        # de VirtualHost do apache 
        proxy_set_header        Host            $host;

        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect          off;
        proxy_buffering         off;

        # passa para o apache
        proxy_pass              http://apache;
   }
}

You will need to configure DNS to route to the Nginx server instead of the Apache remote server. Note that there are many other guidelines available to configure the server. For more information, see: link

Compression is usually enabled in block http of file /etc/nginx/nginx.conf (gzip * directives).

    
07.03.2014 / 22:44