-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
89 lines (71 loc) · 2.06 KB
/
nginx.conf
File metadata and controls
89 lines (71 loc) · 2.06 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log debug;
pid /var/run/nginx.pid;
# Need perl for managing the environment variables
load_module "modules/ngx_http_perl_module.so";
# Expose environment variables that we need
env MESSAGE;
env MESSAGE_FILE;
env TITLE;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
charset UTF-8;
gzip off;
# Extract title from configuration
perl_set $title 'sub {
if(defined $ENV{"TITLE"}) {
$ENV{"TITLE"}
} else {
"TITLE"
}
}';
# Extract message from configuration
perl_set $message 'sub {
use strict;
use warnings;
if(defined $ENV{"MESSAGE"}) {
return $ENV{"MESSAGE"};
} elsif(defined $ENV{"MESSAGE_FILE"}) {
local $/ = undef;
my $message_file = $ENV{"MESSAGE_FILE"};
my $file = "/web/" . $message_file;
open my $fh, "<", $file
or die "could not open $file: $!";
return <$fh>;
} else {
return "MESSAGE or MESSAGE_FILE";
}
}';
server {
listen 80;
server_name localhost;
sendfile off;
root /usr/share/nginx/html;
# Put title and message in placeholders
sub_filter '<!-- MESSAGE -->' '$message';
sub_filter '<!-- TITLE -->' '$title';
sub_filter_once on;
location / {
if ($uri !~ ^/maintenance_files/) {
# Rewrite everything not in maintenance_files otherwise the image
# will be rewritten.
rewrite (.*) /index.html last;
}
expires 0;
add_header Cache-Control private;
}
location /index.html {
index index.html;
}
}
}