Created
October 10, 2014 14:10
-
-
Save m3nd3s/64c474ee0160ba10f86b to your computer and use it in GitHub Desktop.
Nginx: Navegação Liberada por IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Diretiva http {} | |
# | |
http { | |
# ... | |
geo $developer { | |
default no; | |
#177.206.31.159/32 yes; # IP que terá liberação | |
} | |
} | |
# | |
# Diretiva server {} | |
# | |
server { | |
# ... | |
set $maintenance off; | |
# Para ativar o modo bloqueio, usamos um teste de existência do arquivo. | |
# Caso o default seja ficar no modo "manutenção" basta setar a variável acima | |
# como on e não utilizar a parte abaixo. | |
if (-f $document_root/system/maintanence/index.html) { | |
set $maintenance on; | |
} | |
# | |
# Os ifs abaixo eu costumo colocar no final da diretiva server | |
# | |
if ($developer = yes) { | |
set $maintenance off; | |
} | |
if ($maintenance = on) { | |
return 503; | |
} | |
error_page 503 @maintenance; | |
# Direciono para o arquivo que será exibido para quem não tem acesso. | |
location @maintenance { | |
rewrite ^(.*)$ /system/maintanence/index.html break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nota adicional, se for usar imagens no HTML que será exibido para quem não tem permissão, tem que tratar com um if mais ou menos como abaixo, para garantir a exibição da imagem, caso contrário não será renderizada: