2019-03-22 14:01:05 +00:00
|
|
|
|
#
|
|
|
|
|
# You can find a documented example of configuration in ./docs/proxies/nginx.md.
|
|
|
|
|
#
|
2019-01-27 14:54:29 +00:00
|
|
|
|
worker_processes 1;
|
|
|
|
|
|
|
|
|
|
events {
|
|
|
|
|
worker_connections 1024;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http {
|
|
|
|
|
server {
|
2019-03-27 22:09:01 +00:00
|
|
|
|
listen 8080 ssl;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
server_name login.example.com;
|
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
2019-11-02 14:32:58 +00:00
|
|
|
|
set $frontend_endpoint http://authelia-frontend:3000;
|
2020-04-13 23:57:28 +00:00
|
|
|
|
set $backend_endpoint https://authelia-backend:9091;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
|
ssl_certificate /etc/ssl/server.cert;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
2020-03-22 06:04:51 +00:00
|
|
|
|
error_page 497 301 =307 https://$host:$server_port$request_uri;
|
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
|
# Serve the backend API for the portal.
|
|
|
|
|
location /api {
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
2019-04-10 19:27:18 +00:00
|
|
|
|
|
|
|
|
|
# Required by Authelia because "trust proxy" option is used.
|
|
|
|
|
# See https://expressjs.com/en/guide/behind-proxies.html
|
2019-01-27 14:54:29 +00:00
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
2019-04-10 19:27:18 +00:00
|
|
|
|
|
|
|
|
|
# Required by Authelia to build correct links for identity validation.
|
|
|
|
|
proxy_set_header X-Forwarded-Host $http_host;
|
|
|
|
|
|
2019-03-27 22:09:01 +00:00
|
|
|
|
# Needed for network ACLs to work. It appends the IP of the client to the list of IPs
|
|
|
|
|
# and allows Authelia to use it to match the network-based ACLs.
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
|
proxy_intercept_errors on;
|
|
|
|
|
|
|
|
|
|
proxy_pass $backend_endpoint;
|
|
|
|
|
}
|
2019-03-27 22:09:01 +00:00
|
|
|
|
|
|
|
|
|
# Serves the portal application.
|
|
|
|
|
location / {
|
|
|
|
|
# Allow websockets for webpack to auto-reload.
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
proxy_set_header Connection "Upgrade";
|
2019-11-02 14:32:58 +00:00
|
|
|
|
proxy_set_header Host "127.0.0.1";
|
2019-03-27 22:09:01 +00:00
|
|
|
|
|
|
|
|
|
proxy_pass $frontend_endpoint;
|
|
|
|
|
}
|
2019-01-27 14:54:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Serves the home page.
|
2019-01-27 14:54:29 +00:00
|
|
|
|
server {
|
2019-03-27 22:09:01 +00:00
|
|
|
|
listen 8080 ssl;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
server_name home.example.com;
|
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
|
|
|
|
set $upstream_endpoint http://nginx-backend;
|
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
|
ssl_certificate /etc/ssl/server.cert;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
2020-03-22 06:04:51 +00:00
|
|
|
|
error_page 497 301 =307 https://$host:$server_port$request_uri;
|
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
|
location / {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Example configuration of domains protected by Authelia.
|
2019-01-27 14:54:29 +00:00
|
|
|
|
server {
|
2019-03-27 22:09:01 +00:00
|
|
|
|
listen 8080 ssl;
|
2019-03-26 20:00:47 +00:00
|
|
|
|
server_name public.example.com
|
|
|
|
|
admin.example.com
|
|
|
|
|
secure.example.com
|
|
|
|
|
dev.example.com
|
|
|
|
|
singlefactor.example.com
|
|
|
|
|
mx1.mail.example.com mx2.mail.example.com;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
2020-04-13 23:57:28 +00:00
|
|
|
|
set $upstream_verify https://authelia-backend:9091/api/verify;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
set $upstream_endpoint http://nginx-backend;
|
2019-03-26 20:00:47 +00:00
|
|
|
|
set $upstream_headers http://httpbin:8000/headers;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
|
ssl_certificate /etc/ssl/server.cert;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
2020-03-22 06:04:51 +00:00
|
|
|
|
error_page 497 301 =307 https://$host:$server_port$request_uri;
|
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Reverse proxy to the backend. It is protected by Authelia by forwarding authorization checks
|
|
|
|
|
# to the virtual endpoint introduced by nginx and declared in the next block.
|
2019-01-27 14:54:29 +00:00
|
|
|
|
location / {
|
|
|
|
|
auth_request /auth_verify;
|
|
|
|
|
|
2020-10-26 11:38:08 +00:00
|
|
|
|
auth_request_set $user $upstream_http_remote_user;
|
|
|
|
|
proxy_set_header Remote-User $user;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
auth_request_set $groups $upstream_http_remote_groups;
|
|
|
|
|
proxy_set_header Remote-Groups $groups;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2020-10-26 11:38:08 +00:00
|
|
|
|
auth_request_set $name $upstream_http_remote_name;
|
|
|
|
|
proxy_set_header Remote-Name $name;
|
|
|
|
|
|
|
|
|
|
auth_request_set $email $upstream_http_remote_email;
|
|
|
|
|
proxy_set_header Remote-Email $email;
|
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
# Route the request to the correct virtual host in the backend.
|
|
|
|
|
proxy_set_header Host $http_host;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Authelia relies on Proxy-Authorization header to authenticate in basic auth.
|
|
|
|
|
# but for the sake of simplicity (because Authorization in supported in most
|
|
|
|
|
# clients) we take Authorization from the frontend and rewrite it to
|
|
|
|
|
# Proxy-Authorization before sending it to Authelia.
|
|
|
|
|
proxy_set_header Proxy-Authorization $http_authorization;
|
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
# mitigate HTTPoxy Vulnerability
|
|
|
|
|
# https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
|
|
|
|
|
proxy_set_header Proxy "";
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
# Set the `target_url` variable based on the request. It will be used to build the portal
|
|
|
|
|
# URL with the correct redirection parameter.
|
|
|
|
|
set $target_url $scheme://$http_host$request_uri;
|
2019-11-18 23:37:36 +00:00
|
|
|
|
error_page 401 =302 https://login.example.com:8080/?rd=$target_url;
|
2019-04-10 19:27:18 +00:00
|
|
|
|
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Virtual endpoint forwarding requests to Authelia server.
|
2019-01-27 14:54:29 +00:00
|
|
|
|
location /auth_verify {
|
|
|
|
|
internal;
|
2019-04-10 19:27:18 +00:00
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
# Provide either X-Original-URL and X-Forwarded-Proto or
|
2019-04-24 21:52:08 +00:00
|
|
|
|
# X-Forwarded-Proto, X-Forwarded-Host and X-Forwarded-URI or both.
|
2019-04-10 19:27:18 +00:00
|
|
|
|
# Those headers will be used by Authelia to deduce the target url of the user.
|
|
|
|
|
#
|
|
|
|
|
# X-Forwarded-Proto is mandatory since Authelia uses the "trust proxy" option.
|
|
|
|
|
# See https://expressjs.com/en/guide/behind-proxies.html
|
2019-01-27 14:54:29 +00:00
|
|
|
|
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
|
2019-04-10 19:27:18 +00:00
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
2019-04-10 19:27:18 +00:00
|
|
|
|
proxy_set_header X-Forwarded-Host $http_host;
|
2019-04-24 21:52:08 +00:00
|
|
|
|
proxy_set_header X-Forwarded-URI $request_uri;
|
2019-04-10 19:27:18 +00:00
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Authelia can receive Proxy-Authorization to authenticate however most of the clients
|
|
|
|
|
# support Authorization instead. Therefore we rewrite Authorization into Proxy-Authorization.
|
|
|
|
|
proxy_set_header Proxy-Authorization $http_authorization;
|
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
|
proxy_pass_request_body off;
|
|
|
|
|
proxy_set_header Content-Length "";
|
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
proxy_pass $upstream_verify;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Used by suites to test the forwarded users and groups headers produced by Authelia.
|
2019-03-03 22:51:52 +00:00
|
|
|
|
location /headers {
|
|
|
|
|
auth_request /auth_verify;
|
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
auth_request_set $user $upstream_http_remote_user;
|
2020-05-06 01:50:37 +00:00
|
|
|
|
proxy_set_header Remote-User $user;
|
2019-03-03 22:51:52 +00:00
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
auth_request_set $groups $upstream_http_remote_groups;
|
2020-05-06 01:50:37 +00:00
|
|
|
|
proxy_set_header Remote-Groups $groups;
|
2019-03-03 22:51:52 +00:00
|
|
|
|
|
2020-10-26 11:38:08 +00:00
|
|
|
|
auth_request_set $name $upstream_http_remote_name;
|
|
|
|
|
proxy_set_header Remote-Name $name;
|
|
|
|
|
|
|
|
|
|
auth_request_set $email $upstream_http_remote_email;
|
|
|
|
|
proxy_set_header Remote-Email $email;
|
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
set $target_url $scheme://$http_host$request_uri;
|
2019-11-18 23:37:36 +00:00
|
|
|
|
error_page 401 =302 https://login.example.com:8080/?rd=$target_url;
|
2019-03-03 22:51:52 +00:00
|
|
|
|
|
2019-04-10 19:27:18 +00:00
|
|
|
|
proxy_pass $upstream_headers;
|
2019-03-03 22:51:52 +00:00
|
|
|
|
}
|
2019-01-27 14:54:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Fake Web Mail used to receive emails sent by Authelia.
|
2019-01-27 14:54:29 +00:00
|
|
|
|
server {
|
2019-03-27 22:09:01 +00:00
|
|
|
|
listen 8080 ssl;
|
2019-03-26 20:00:47 +00:00
|
|
|
|
server_name mail.example.com;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
2019-03-26 20:00:47 +00:00
|
|
|
|
set $upstream_endpoint http://smtp:1080;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
|
ssl_certificate /etc/ssl/server.cert;
|
2019-01-27 14:54:29 +00:00
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
2020-03-22 06:04:51 +00:00
|
|
|
|
error_page 497 301 =307 https://$host:$server_port$request_uri;
|
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
|
location / {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-24 14:15:49 +00:00
|
|
|
|
|
2019-03-26 20:00:47 +00:00
|
|
|
|
# Fake API emulating Duo behavior
|
2019-03-24 14:15:49 +00:00
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
server_name duo.example.com;
|
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
|
|
|
|
set $upstream_endpoint http://duo-api:3000;
|
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
|
ssl_certificate /etc/ssl/server.cert;
|
2019-03-24 14:15:49 +00:00
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
2020-03-22 06:04:51 +00:00
|
|
|
|
error_page 497 301 =307 https://$host:$server_port$request_uri;
|
|
|
|
|
|
2019-03-24 14:15:49 +00:00
|
|
|
|
location / {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-27 22:09:01 +00:00
|
|
|
|
|
|
|
|
|
# Matches all domains. It redirects to the home page.
|
|
|
|
|
server {
|
|
|
|
|
listen 8080 ssl;
|
|
|
|
|
server_name _;
|
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
|
ssl_certificate /etc/ssl/server.cert;
|
2019-03-27 22:09:01 +00:00
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
return 301 https://home.example.com:8080/;
|
|
|
|
|
}
|
2019-01-27 14:54:29 +00:00
|
|
|
|
}
|
|
|
|
|
|