Created
January 22, 2020 18:28
-
-
Save arkag/1186c12ddbce79413c4f648ed2a8c1cf to your computer and use it in GitHub Desktop.
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
server { | |
server_name sub.domain.com; | |
root /usr/share/nginx/html; | |
index index.php index.html index.htm; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
location /stats { | |
return 302 /stats/; | |
} | |
location ~ ^/stats/(.*)$ { | |
auth_request /validate; | |
rewrite /stats/(.*) /$1 break; | |
proxy_pass http://localhost:5601; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_set_header X-Vouch-User $auth_resp_x_vouch_user; | |
proxy_cache_bypass $http_upgrade; | |
} | |
location ~ \.php$ { | |
try_files $uri =404; | |
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# Any request to this server will first be sent to this URL | |
location = /validate { | |
# forward the /validate request to Vouch Proxy | |
proxy_pass http://127.0.0.1:9090/validate; | |
# be sure to pass the original host header | |
proxy_set_header Host $http_host; | |
# Vouch Proxy only acts on the request headers | |
proxy_pass_request_body off; | |
proxy_set_header Content-Length ""; | |
# optionally add X-Vouch-User as returned by Vouch Proxy along with the request | |
auth_request_set $auth_resp_x_vouch_user $upstream_http_x_vouch_user; | |
# optionally add X-Vouch-IdP-Claims-* custom claims you are tracking | |
# auth_request_set $auth_resp_x_vouch_idp_claims_groups $upstream_http_x_vouch_idp_claims_groups; | |
# auth_request_set $auth_resp_x_vouch_idp_claims_given_name $upstream_http_x_vouch_idp_claims_given_name; | |
# optinally add X-Vouch-IdP-AccessToken or X-Vouch-IdP-IdToken | |
# auth_request_set $auth_resp_x_vouch_idp_accesstoken $upstream_http_x_vouch_idp_accesstoken; | |
# auth_request_set $auth_resp_x_vouch_idp_idtoken $upstream_http_x_vouch_idp_idtoken; | |
# these return values are used by the @error401 call | |
auth_request_set $auth_resp_jwt $upstream_http_x_vouch_jwt; | |
auth_request_set $auth_resp_err $upstream_http_x_vouch_err; | |
auth_request_set $auth_resp_failcount $upstream_http_x_vouch_failcount; | |
# Vouch Proxy can run behind the same Nginx reverse proxy | |
# may need to comply to "upstream" server naming | |
# proxy_pass http://sub.domain.com/validate; | |
# proxy_set_header Host $http_host; | |
} | |
error_page 401 = @error401; | |
# If the user is not logged in, redirect them to Vouch's login URL | |
location @error401 { | |
return 302 https://sub.domain.com:9090/login?url=$scheme://$http_host$request_uri&vouch-failcount=$auth_resp_failcount&X-Vouch-Token=$auth_resp_jwt&error=$auth_resp_err; | |
} | |
listen 443 ssl; # managed by Certbot | |
ssl_certificate /etc/letsencrypt/live/sub.domain.com/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/sub.domain.com/privkey.pem; # managed by Certbot | |
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot | |
} | |
server { | |
if ($host = sub.domain.com) { | |
return 301 https://$host$request_uri; | |
} # managed by Certbot | |
listen 80; | |
server_name sub.domain.com; | |
return 404; # managed by Certbot | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment