Created
April 17, 2020 13:37
-
-
Save osmanmakal/0b046b00f6b8e6f34e75dde9b96da48f to your computer and use it in GitHub Desktop.
Sample maintenance work file prepared for Lua supported Nginx. You can customize it as you like.
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
| -- Sample maintenance work file prepared for Lua supported Nginx. You can customize it as you like. | |
| -- Note: It works within websites that work with | |
| -- services such as Reverse proxy and CloudFlare, | |
| -- and you can create a special article or html | |
| -- page by changing ngx.exit(ngx.HTTP_FORBIDDEN) | |
| local whitelist = { | |
| "192.168.1.2", | |
| "192.168.1.3", | |
| } | |
| local remote_addr = "" | |
| if ngx.var.http_cf_connecting_ip ~= nil then | |
| remote_addr = ngx.var.http_cf_connecting_ip | |
| elseif ngx.var.http_x_forwarded_for ~= nil then | |
| remote_addr = ngx.var.http_x_forwarded_for | |
| else | |
| remote_addr = ngx.var.remote_addr | |
| end | |
| local function check(ips) | |
| local ips_length = #ips | |
| for i=1,ips_length do | |
| local value = ips[i] | |
| if value == remote_addr then | |
| return | |
| end | |
| end | |
| return ngx.exit(ngx.HTTP_FORBIDDEN) | |
| end | |
| check(whitelist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment