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

Asked

Viewed 1,547 times

4

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

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

Thus, we reduce the costs of hosting without losing in performance.

Bottom line: I want to cache using Nginx from a server in the US that runs apache2. All tutorials I found were related to running Nginx and apache on the same machine and/or worked only for one site, requiring manual configuration for each additional client.

  • What is your doubt?

  • 1

    Guys, this question here is not very wide, and is not so badly explained. Yes to keep it here in Sopt.

  • @Yan when the information you will add in the comment is pertinent to the question, edit the question and add in it the comment.

  • @Emersonrochaluiz, thanks for the touch. I corrected.

1 answer

2

Simply forward the requests made to your server running Nginx and pass it to the external server in the same way you would route it to a local apache. This is an example configuration (it is usually 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 forward to the Nginx server instead of the remote server with Apache. Note that there are many other guidelines available to configure the server. For more information, see: http://wiki.nginx.org/HttpProxyModule

Compression is usually enabled in the block http of the archive /etc/nginx/nginx.conf (gzip guidelines*).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.