Last active
November 11, 2022 00:07
-
-
Save nginx-gists/418407ef09ea03f4805da3d29270a392 to your computer and use it in GitHub Desktop.
Announcing NGINX Plus R24
This file contains 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
var response = ""; | |
function maskAwsKeys(r, data, flags) { | |
response += data; // Collect the entire response, | |
if (flags.last) { // until we get the last byte. | |
var masked = response.replace(/([^A-Z0-9]|^)(AKIA|A3T|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)([A-Z0-9]{12,})/g, | |
function ($0, $1) { | |
return $1 + (new Array($0.length).join('*')); | |
} | |
); | |
r.sendBuffer(masked, flags); | |
} | |
} | |
export default { maskAwsKeys } |
This file contains 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
location /private/ { | |
auth_jwt "Private"; | |
auth_jwt_type encrypted; | |
auth_jwt_key_file conf/api_secret.jwk; | |
proxy_pass http://my_backend; | |
} | |
# vim: syntax=nginx |
This file contains 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
upstream my_backend { | |
zone my_backend 64k; | |
server 10.0.0.1; | |
server 10.0.0.2; | |
} | |
server { | |
#... | |
location / { | |
proxy_pass http://my_backend; | |
health_check mandatory persistent; | |
} | |
} | |
# vim: syntax=nginx |
This file contains 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
js_import conf.d/cookies.js; | |
keyval_zone zone=cookie_jar:16M; | |
keyval $cookie_session $cookies zone=cookie_jar; | |
keyval $request_id $new_session zone=cookie_jar; | |
server { | |
listen 80; | |
location / { | |
proxy_pass http://my_backend; | |
proxy_set_header Cookie $cookies; # Replace reference cookie with original | |
js_header_filter cookies.jar; # Intercept and replace Set-Cookie | |
} | |
} | |
# vim: syntax=nginx |
This file contains 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
js_import conf.d/filter.js; | |
server { | |
listen 80; | |
location / { | |
proxy_pass http://my_backend; | |
js_body_filter filter.maskAwsKeys; | |
} | |
} | |
# vim: syntax=nginx |
This file contains 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
stream { | |
js_import stream.js; | |
server { | |
listen 3306; # MySQL default port | |
js_access stream.access; | |
proxy_pass mysql_backend; | |
} | |
} | |
# vim: syntax=nginx |
This file contains 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
function access(s) { | |
ngx.fetch('http://127.0.0.1:8085/') | |
.then(response => { | |
if (response.ok) { | |
s.allow(); | |
return; | |
} | |
}) | |
.then(body => {}) | |
.catch(e => r.return(501, e.message)) | |
s.deny(); | |
return; | |
} | |
export default { access } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For a discussion of these files, see Announcing NGINX Plus R24