Nginx truques


Redirecionar http para https

Atrás de um ELB

Se o nginx estiver atrás de um ELB, precisa checar o `http_x_forwaraded_proto` para nao ter problemas de `too many requests`

# Escopo: Dentro de um server {} / location {} / if {}
if ($http_x_forwarded_proto != 'https') {
  rewrite ^ https://$host$request_uri? permanent;
}

Sem ELB

# Escopo: dentro de um server {} / location {} / if {}
return 301 https://$server_name$request_uri;

Traduzir

https://easyengine.io/tutorials/nginx/log-parsing/

Magica com os logs

Com o log default do NGINX é possível usar Cat / Grep / CUT para recuperar umas informações ou até mesmo estatísticas!

Cat / Grep / Awk / Cut

To check your access by the HTTP code

cat  stratus.access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -rn

Which URL generated your those 500 errors:

awk '($9 ~ /500/)' access.log | awk '{print $7}' | sort | uniq -c | sort -rn

Check how many times each IP hit your app:

awk '{print $1}' access.log | sort | uniq -c | sort -nr

Check the full log of those 500 requests:

grep -E '" 5[0-9]{2}' access.log