0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · Aula

Reforçando a segurança do Nginx com cabeçalhos

Adicione cabeçalhos de segurança HTTP no Nginx para se defender contra ataques de clickjacking, detecção indevida de MIME e injeção de conteúdo.

Reforçando a segurança do Nginx com cabeçalhos é uma aula grátis de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Headers as a Defense Layer

Beyond TLS and authentication, modern browsers honor security headers that instruct them how to behave. Nginx can inject these on every response with the add_header directive.

Preventing MIME Sniffing

X-Content-Type-Options: nosniff stops browsers from guessing a resource's type, blocking attacks that disguise a script as an image.

add_header X-Content-Type-Options "nosniff" always;

Blocking Clickjacking

X-Frame-Options controls whether your site can be embedded in a frame. Use DENY or SAMEORIGIN to prevent clickjacking.

add_header X-Frame-Options "SAMEORIGIN" always;

Strict Transport Security

HSTS forces browsers to use HTTPS for future visits. Set a long max-age once HTTPS is stable everywhere.

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Content Security Policy

A Content-Security-Policy restricts where scripts, styles, and other resources may load from, mitigating cross-site scripting.

add_header Content-Security-Policy "default-src 'self'" always;

Controlling the Referrer

Referrer-Policy limits how much referrer information leaks to other sites when users click outbound links.

add_header Referrer-Policy "strict-origin-when-cross-origin" always;

Why the always Flag

Without always, Nginx adds the header only on successful responses (2xx, 3xx). The always flag ensures the header is present on error responses too.

add_header X-Frame-Options "DENY" always;

Hiding the Nginx Version

By default Nginx reveals its version in the Server header and error pages. Turn this off to give attackers less information.

server_tokens off;

The add_header Inheritance Trap

If a location block has its own add_header, it replaces all inherited headers from the parent. Re-declare needed headers in nested blocks.

# headers in http/server are dropped here
location /api {
    add_header X-Content-Type-Options "nosniff" always;
}

Grouping Security Headers

Keep all security headers in one include file and pull it into each server block for consistency.

# security_headers.conf
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

# server block:
include /etc/nginx/security_headers.conf;

Verifying Headers

Use curl to inspect the response headers and confirm each one is present, even on error responses.

curl -I https://example.com

Quick Check

Which header tells the browser to refuse loading your site inside a frame on another domain?

Recap

You hardened Nginx with browser security headers:

  • nosniff blocks MIME confusion
  • X-Frame-Options stops clickjacking
  • HSTS enforces HTTPS, CSP restricts resources
  • Use always and beware add_header inheritance
  • server_tokens off hides the version

These complement TLS and authentication for defense in depth.

Perguntas Frequentes

A aula “Reforçando a segurança do Nginx com cabeçalhos” é grátis?

Sim — o texto completo de “Reforçando a segurança do Nginx com cabeçalhos” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), atualize para CoddyKit PRO. O curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) inclui 4 aulas no total.

O que vou aprender em “Reforçando a segurança do Nginx com cabeçalhos”?

Adicione cabeçalhos de segurança HTTP no Nginx para se defender contra ataques de clickjacking, detecção indevida de MIME e injeção de conteúdo. Você pratica API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Nenhuma experiência prévia é necessária. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Reforçando a segurança do Nginx com cabeçalhos”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Sim. Cada aula de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Protegendo o Nginx com SSL/TLS
  2. HTTP/2 e Otimização do Nginx
  3. Autenticação Básica e Controle de Acesso
  4. Reforçando a segurança do Nginx com cabeçalhos
← Voltar para API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)