-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9d6b915
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2015 The Kubernetes Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
#FROM nginx:1.24.0-alpine3.17-slim | ||
#FROM nginx:1.26.1-alpine3.19-slim | ||
#RUN apk add --no-cache nginx-mod-http-lua | ||
#FROM fabiocicerchia/nginx-lua:1.27.0-alpine3.20.1 | ||
#RUN rm -rf /etc/nginx/conf.d | ||
#FROM nginx:1.26.1-alpine3.19-slim | ||
#FROM nginx:1.27.0-alpine3.19 | ||
#RUN apk update && apk add --no-cache nginx-plus-module-lua | ||
#ADD nginx.conf /etc/nginx/nginx.conf | ||
#ADD README.md README.md | ||
|
||
FROM alpine:3.17.8 | ||
|
||
RUN apk add --no-cache nginx-mod-http-lua | ||
|
||
# Create folder for PID file | ||
RUN mkdir -p /run/nginx | ||
|
||
# Add custom nginx conf | ||
COPY ./nginx.conf /etc/nginx/nginx.conf | ||
|
||
ENTRYPOINT ["nginx"] | ||
CMD ["-c", "/etc/nginx/nginx.conf"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Echoserver | ||
|
||
This is a simple server that responds with the http headers it received. | ||
Image versions >= 1.4 removes the redirect introduced in 1.3. | ||
Image versions >= 1.3 redirect requests on :80 with `X-Forwarded-Proto: http` to :443. | ||
Image versions > 1.0 run an nginx server, and implement the echoserver using lua in the nginx config. | ||
Image versions <= 1.0 run a python http server instead of nginx, and don't redirect any requests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
load_module /usr/lib/nginx/modules/ndk_http_module.so; | ||
load_module /usr/lib/nginx/modules/ngx_http_lua_module.so; | ||
|
||
pcre_jit on; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
env HOSTNAME; | ||
env NODE_NAME; | ||
env POD_NAME; | ||
env POD_NAMESPACE; | ||
env POD_IP; | ||
|
||
http { | ||
default_type 'text/plain'; | ||
# maximum allowed size of the client request body. By default this is 1m. | ||
# Request with bigger bodies nginx will return error code 413. | ||
# http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size | ||
client_max_body_size 10m; | ||
|
||
init_by_lua_block { | ||
local template = require("template") | ||
-- template syntax documented here: | ||
-- https://github.com/bungle/lua-resty-template/blob/master/README.md | ||
tmpl = template.compile([[ | ||
|
||
|
||
Hostname: {{os.getenv("HOSTNAME") or "N/A"}} | ||
|
||
Pod Information: | ||
{% if os.getenv("POD_NAME") then %} | ||
node name: {{os.getenv("NODE_NAME") or "N/A"}} | ||
pod name: {{os.getenv("POD_NAME") or "N/A"}} | ||
pod namespace: {{os.getenv("POD_NAMESPACE") or "N/A"}} | ||
pod IP: {{os.getenv("POD_IP") or "N/A"}} | ||
{% else %} | ||
-no pod information available- | ||
{% end %} | ||
|
||
Server values: | ||
server_version=nginx: {{ngx.var.nginx_version}} - lua: {{ngx.config.ngx_lua_version}} | ||
|
||
Request Information: | ||
client_address={{ngx.var.remote_addr}} | ||
method={{ngx.req.get_method()}} | ||
real path={{ngx.var.request_uri}} | ||
query={{ngx.var.query_string or ""}} | ||
request_version={{ngx.req.http_version()}} | ||
request_scheme={{ngx.var.scheme}} | ||
request_uri={{ngx.var.scheme.."://"..ngx.var.host..":"..ngx.var.server_port..ngx.var.request_uri}} | ||
|
||
Request Headers: | ||
{% for i, key in ipairs(keys) do %} | ||
{{key}}={{headers[key]}} | ||
{% end %} | ||
|
||
Request Body: | ||
{{ngx.var.request_body or " -no body in request-"}} | ||
]]) | ||
} | ||
|
||
server { | ||
# please check the benefits of reuseport https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1 | ||
# basically instructs to create an individual listening socket for each worker process (using the SO_REUSEPORT | ||
# socket option), allowing a kernel to distribute incoming connections between worker processes. | ||
listen 8080 default_server reuseport; | ||
listen 8443 default_server ssl http2 reuseport; | ||
|
||
ssl_certificate /certs/certificate.crt; | ||
ssl_certificate_key /certs/privateKey.key; | ||
|
||
# Replace '_' with your hostname. | ||
server_name _; | ||
|
||
location / { | ||
lua_need_request_body on; | ||
content_by_lua_block { | ||
ngx.header["Server"] = "echoserver" | ||
|
||
local headers = ngx.req.get_headers() | ||
local keys = {} | ||
for key, val in pairs(headers) do | ||
table.insert(keys, key) | ||
end | ||
table.sort(keys) | ||
|
||
ngx.say(tmpl({os=os, ngx=ngx, keys=keys, headers=headers})) | ||
} | ||
} | ||
} | ||
} |