-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnginx.config.sample
69 lines (60 loc) · 1.67 KB
/
nginx.config.sample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Simple example, ie. a simple static website
server {
listen 443 ssl;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
server_name examplehost.com;
location @error401 {
return 302 https://examplehost.com/login?follow_page=$scheme://$http_host$request_uri;
}
# Authentication related endpoints
location ~ /(auth|login|logout)$ {
include fastcgi_params;
fastcgi_pass unix:/var/www/totp_auth/sock;
}
# Website root
location / {
auth_request /auth;
error_page 401 = @error401;
root /path/to/static/website;
}
}
# Use alternative paths for /login and /logout in case they are already in use
server {
listen 443 ssl;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
server_name examplehost.com;
location @error401 {
return 302 https://examplehost.com/login?follow_page=$scheme://$http_host$request_uri;
}
# Authentication related endpoints
location ~ /auth $ {
include fastcgi_params;
fastcgi_pass unix:/var/www/totp_auth/sock;
}
location ~ /your/path/of/choice/login $ {
include fastcgi_params;
rewrite ^/.*$ /login break;
fastcgi_pass unix:/var/www/totp_auth/sock;
}
location ~ /your/path/of/choice/logout $ {
include fastcgi_params;
rewrite ^/.*$ /logout break;
fastcgi_pass unix:/var/www/totp_auth/sock;
}
# Website root (ie. a PHP website)
location / {
auth_request /auth;
error_page 401 = @error401;
root /path/to/website;
}
location ~ \.php$ {
auth_request /auth;
error_page 401 = @error401;
root /path/to/website;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}