Headers-More#

O módulo headers-more permite adicionar, definir ou remover qualquer cabeçalho de saída ou entrada.

Instalação#

Para instalar o módulo, use um dos seguintes pacotes:

  • Angie: angie-module-headers-more

  • Angie PRO: angie-pro-module-headers-more

Carregando o Módulo#

Para usar o módulo, ele deve ser carregado no contexto de main{}:

load_module modules/ngx_http_headers_more_filter_module.so;

No exemplo de configuração abaixo, diretivas do módulo echo também são usadas junto com as diretivas do próprio módulo. Carregando o módulo echo:

load_module modules/ngx_http_echo_module.so;

Exemplo de Configuração#

http {
    server {
        listen 80;

        root  /usr/share/angie/html;
        index index.html index.htm;

        location /clear {
            more_clear_headers 'Content-Type';
            proxy_pass http://127.0.0.1:8081;
        }

        location /settype {
            more_set_headers 'Content-Type: text/plain';
            proxy_pass http://127.0.0.1:8081;
        }

        location /changetype {
            more_set_headers -t 'text/plain text/css' 'Content-Type: text/newtype';
            proxy_pass http://127.0.0.1:8081;
        }

        location /newheader {
            more_set_headers -t 'text/plain text/css' 'New-Header: foo';
            proxy_pass http://127.0.0.1:8081;
        }

        location /404 {
            more_set_headers -s '400 404 500 503' 'Upstream-Status: $upstream_status';
            proxy_pass http://127.0.0.1:8081;
        }

        location /input {
            set $my_host 'my.host';
            more_set_input_headers 'Host: $my_host';
            more_set_input_headers -t 'text/plain' 'X-Foo: bar';

            echo "Host: $host";
            echo "X-foo: $http_x_foo";
        }
    }

    server {
        listen 8081;
        default_type text/css;

        location / {
            return 200 "OK\n";
        }

        location /404 {
            return 404 "Done\n";
        }
    }
}

Informações Adicionais#

Documentação detalhada e código-fonte estão disponíveis em: openresty/headers-more-nginx-module