- https://nginx.org/en/docs/njs/
- https://github.com/nginx/njs-examples#authorizing-requests-using-auth-request-http-authorization-auth-request
# /etc/nginx/site-enable/custom-host.conf
http {
js_path "/etc/nginx/njs/";
js_import main from authorize.js;
upstream backend1 {
server 127.0.0.1:8081;
}
upstream backend2 {
server 127.0.0.1:8082;
}
server {
listen 80;
location / {
js_content main.authorize;
}
location @app-backend1 {
proxy_pass http://backend1;
}
location @app-backend2 {
proxy_pass http://backend2;
}
}
}
// /etc/nginx/njs/authorize.js
function authorize(r) {
var body = r.requestText;
if (r.uri.indexOf('someValue') > -1 || JSON.stringify(r.args).indexOf('someValue') > -1 || String(body).indexOf('someValue') > -1)
{
r.internalRedirect('@app-backend1');
}
else
{
r.internalRedirect('@app-backend2');
}
}
export default {authorize}
반응형
'server-side > nginx' 카테고리의 다른 글
Access to the script ‘xxx’ has been denied (see security.limit_extensions) (0) | 2018.07.21 |
---|---|
nginx Verify return code: 21 (unable to verify the first certificate) (0) | 2017.03.06 |
Centos7 Nignx php-fpm 502 Bad Gateway (0) | 2017.02.16 |
MAC Bitnami Nginx Stack Bind Error (0) | 2016.01.12 |
nginx 301 redirect (0) | 2014.06.05 |