2019-03-22 21:01:05 +07:00
|
|
|
|
#
|
|
|
|
|
# You can find a documented example of configuration in ./docs/proxies/nginx.md.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
2019-01-27 21:54:29 +07:00
|
|
|
|
worker_processes 1;
|
|
|
|
|
|
|
|
|
|
events {
|
|
|
|
|
worker_connections 1024;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http {
|
|
|
|
|
<% if (production) { %>
|
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
server_name login.example.com;
|
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
2019-03-02 23:15:28 +07:00
|
|
|
|
set $backend_endpoint <%= authelia_backend %>;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
ssl_certificate /etc/ssl/server.crt;
|
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
|
|
|
|
# Serves the portal application.
|
|
|
|
|
location / {
|
|
|
|
|
proxy_pass $backend_endpoint/index.html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location /static {
|
|
|
|
|
proxy_pass $backend_endpoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Serve the backend API for the portal.
|
|
|
|
|
location /api {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_set_header X-Original-URI $request_uri;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
proxy_intercept_errors on;
|
|
|
|
|
|
|
|
|
|
proxy_pass $backend_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<% } else { %>
|
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
server_name login.example.com;
|
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
|
|
|
|
set $frontend_endpoint http://192.168.240.1:3000;
|
2019-03-02 23:15:28 +07:00
|
|
|
|
set $backend_endpoint <%= authelia_backend %>;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
ssl_certificate /etc/ssl/server.crt;
|
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
|
|
|
|
# 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";
|
|
|
|
|
|
|
|
|
|
proxy_pass $frontend_endpoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Serve the backend API for the portal.
|
|
|
|
|
location /api {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_set_header X-Original-URI $request_uri;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
proxy_intercept_errors on;
|
|
|
|
|
|
|
|
|
|
proxy_pass $backend_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<% } %>
|
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
# Serves the home page.
|
2019-01-27 21:54:29 +07:00
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
server_name home.example.com;
|
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
|
|
|
|
set $upstream_endpoint http://nginx-backend;
|
|
|
|
|
|
|
|
|
|
ssl_certificate /etc/ssl/server.crt;
|
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
# Example configuration of domains protected by Authelia.
|
2019-01-27 21:54:29 +07:00
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
2019-03-27 03:00:47 +07: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 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
2019-03-02 23:15:28 +07:00
|
|
|
|
set $upstream_verify <%= authelia_backend %>/api/verify;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
set $upstream_endpoint http://nginx-backend;
|
2019-03-27 03:00:47 +07:00
|
|
|
|
set $upstream_headers http://httpbin:8000/headers;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
ssl_certificate /etc/ssl/server.crt;
|
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
2019-03-27 03:00:47 +07: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 21:54:29 +07:00
|
|
|
|
location / {
|
|
|
|
|
auth_request /auth_verify;
|
|
|
|
|
|
|
|
|
|
auth_request_set $redirect $upstream_http_redirect;
|
|
|
|
|
|
|
|
|
|
auth_request_set $user $upstream_http_remote_user;
|
|
|
|
|
proxy_set_header X-Forwarded-User $user;
|
|
|
|
|
|
|
|
|
|
auth_request_set $groups $upstream_http_remote_groups;
|
|
|
|
|
proxy_set_header Remote-Groups $groups;
|
|
|
|
|
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
|
2019-03-27 03:00:47 +07: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-03-04 05:51:52 +07:00
|
|
|
|
error_page 401 =302 https://login.example.com:8080/#/?rd=$redirect;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
# Virtual endpoint forwarding requests to Authelia server.
|
2019-01-27 21:54:29 +07:00
|
|
|
|
location /auth_verify {
|
|
|
|
|
internal;
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
|
|
|
|
|
proxy_set_header X-Original-URI $request_uri;
|
|
|
|
|
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
2019-03-27 03:00:47 +07: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 21:54:29 +07:00
|
|
|
|
proxy_pass_request_body off;
|
|
|
|
|
proxy_set_header Content-Length "";
|
|
|
|
|
|
|
|
|
|
proxy_pass $upstream_verify;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
# Used by suites to test the forwarded users and groups headers produced by Authelia.
|
2019-03-04 05:51:52 +07:00
|
|
|
|
location /headers {
|
|
|
|
|
auth_request /auth_verify;
|
|
|
|
|
|
|
|
|
|
auth_request_set $redirect $upstream_http_redirect;
|
|
|
|
|
|
|
|
|
|
auth_request_set $user $upstream_http_remote_user;
|
|
|
|
|
proxy_set_header Custom-Forwarded-User $user;
|
|
|
|
|
|
|
|
|
|
auth_request_set $groups $upstream_http_remote_groups;
|
|
|
|
|
proxy_set_header Custom-Forwarded-Groups $groups;
|
|
|
|
|
|
|
|
|
|
error_page 401 =302 https://login.example.com:8080/#/?rd=$redirect;
|
|
|
|
|
|
|
|
|
|
proxy_pass $upstream_headers;
|
|
|
|
|
}
|
2019-01-27 21:54:29 +07:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
# Matches all domains. It redirects to the home page.
|
2019-01-27 21:54:29 +07:00
|
|
|
|
server {
|
2019-03-27 03:00:47 +07:00
|
|
|
|
listen 443 ssl;
|
|
|
|
|
server_name _;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
ssl_certificate /etc/ssl/server.crt;
|
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
return 301 https://home.example.com:8080/;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
# Fake Web Mail used to receive emails sent by Authelia.
|
2019-01-27 21:54:29 +07:00
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
2019-03-27 03:00:47 +07:00
|
|
|
|
server_name mail.example.com;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
2019-03-27 03:00:47 +07:00
|
|
|
|
set $upstream_endpoint http://smtp:1080;
|
2019-01-27 21:54:29 +07:00
|
|
|
|
|
|
|
|
|
ssl_certificate /etc/ssl/server.crt;
|
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-24 21:15:49 +07:00
|
|
|
|
|
2019-03-27 03:00:47 +07:00
|
|
|
|
# Fake API emulating Duo behavior
|
2019-03-24 21:15:49 +07:00
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
server_name duo.example.com;
|
|
|
|
|
|
|
|
|
|
resolver 127.0.0.11 ipv6=off;
|
|
|
|
|
set $upstream_endpoint http://duo-api:3000;
|
|
|
|
|
|
|
|
|
|
ssl_certificate /etc/ssl/server.crt;
|
|
|
|
|
ssl_certificate_key /etc/ssl/server.key;
|
|
|
|
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN";
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_pass $upstream_endpoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-27 21:54:29 +07:00
|
|
|
|
}
|
|
|
|
|
|