-
Notifications
You must be signed in to change notification settings - Fork 15
/
nginx.conf
107 lines (84 loc) · 3.25 KB
/
nginx.conf
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
env AWS_ACCESS_KEY_ID;
env AWS_ACCESS_KEY_SECRET;
env AWS_REGION;
env AWS_SERVICE;
env AWS_HOST;
http {
lua_package_path '/usr/local/share/lua/5.1/?.lua;;';
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server_tokens off;
server {
listen 8080;
server_name localhost;
client_max_body_size 100M;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
set $backend ''; # 初始化变量
# modify request headers
access_by_lua_block {
local aws_auth = require "resty.aws_auth"
local aws_host = os.getenv("AWS_HOST")
ngx.var.backend = aws_host
local aws_key = os.getenv("AWS_ACCESS_KEY_ID")
local aws_secret = os.getenv("AWS_ACCESS_KEY_SECRET")
local aws_region = os.getenv("AWS_REGION")
local aws_service = os.getenv("AWS_SERVICE")
local headers = ngx.req.get_headers()
for k, v in pairs(headers) do
ngx.log(ngx.INFO, "headers before setting: ", k, ": ", v)
end
local config = {
aws_host = aws_host,
aws_key = aws_key,
aws_secret = aws_secret,
aws_region = aws_region,
aws_service = aws_service,
content_type = headers["content-type"] or "application/x-www-form-urlencoded",
request_method = ngx.req.get_method(),
request_path = ngx.var.uri,
request_body = ngx.req.get_body_data(),
request_querystr = ngx.var.query_string
}
-- addtional logging
ngx.log(ngx.INFO, "request_path: ", config.request_path)
ngx.log(ngx.INFO, "request_querystr: ", config.request_querystr)
local aws = aws_auth:new(config)
-- set aws auth headers
aws:set_ngx_auth_headers()
local headers2 = ngx.req.get_headers()
for k, v in pairs(headers2) do
ngx.log(ngx.INFO, "headers after setting: ", k, ": ", v)
end
}
proxy_pass "http://$backend";
proxy_set_header Host $backend;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}