Last active
November 8, 2019 13:42
-
-
Save sairamkrish/6ca1173c9e5b80d41fa5aa29682c698e to your computer and use it in GitHub Desktop.
Nginx configuration to work with Keycloak as Auth layer
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
server { | |
listen 80 default_server; | |
root /opt/nginx/html; | |
resolver 127.0.0.11 valid=1s ipv6=off; | |
access_by_lua ' | |
local opts = { | |
redirect_uri_path = "/redirect_uri", | |
accept_none_alg = true, | |
discovery = "http://host.docker.internal:3333/auth/realms/myrealm/.well-known/openid-configuration", | |
client_id = "nginx", | |
client_secret = "your-client-secret", | |
redirect_uri_scheme = "http", | |
logout_path = "/logout", | |
redirect_after_logout_uri = "http://host.docker.internal:3333/auth/realms/myrealm/protocol/openid-connect/logout?redirect_uri=http://localhost/", | |
redirect_after_logout_with_id_token_hint = false, | |
session_contents = {id_token=true} | |
} | |
-- call introspect for OAuth 2.0 Bearer Access Token validation | |
local res, err = require("resty.openidc").authenticate(opts) | |
if err then | |
ngx.status = 403 | |
ngx.say(err) | |
ngx.exit(ngx.HTTP_FORBIDDEN) | |
end | |
'; | |
# I disabled caching so the browser won't cache the site. | |
expires 0; | |
add_header Cache-Control private; | |
location / { | |
} | |
# redirect server error pages to the static page /40x.html | |
# | |
error_page 404 /404.html; | |
location = /40x.html { | |
} | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment