Skip to content

Instantly share code, notes, and snippets.

@joseEkcit
Created March 31, 2025 11:44
Show Gist options
  • Save joseEkcit/079a26489093337ba2a65431e92919d4 to your computer and use it in GitHub Desktop.
Save joseEkcit/079a26489093337ba2a65431e92919d4 to your computer and use it in GitHub Desktop.
Example nginx configuration for FusionAuth SSO bootstrap
upstream auth {
server 0.0.0.0:9011;
keepalive 8;
}
server {
server_name auth.mydomain.tld;
access_log /var/log/nginx/auth-access.log;
# Other previous server configuration...
location /oauth2/authorize {
# Add the Authorization header only if the cookie is present
# Initialize variables
set $auth_token "";
set $auth_header "";
# Extract the cookie value from the Cookie header
if ($http_cookie ~* "myfusionssoauthtoken=([^;]+)") {
set $auth_token $1;
}
# Only set Authorization header if the token is not empty
if ($auth_token != "") {
set $auth_header "Bearer $auth_token";
}
proxy_set_header Authorization $auth_header;
proxy_pass http://auth;
proxy_set_header X-Robots-Tag "noindex, nofollow";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Port "443";
proxy_set_header X-Forwarded-Proto "https";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Rest of the server configuration...
}
@joseEkcit
Copy link
Author

This file shows an example on how to set up the /oauth2/authorize location in nginx to pass the value of a cookie called "myfusionssoauthtoken" as a request header to be consumed in the SSO session bootstrap flow. It's not a full nginx configuration file for FusionAuth, refer to FusionAuth docs for an example of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment