1
0
mirror of https://github.com/dcarrillo/docker-nginx.git synced 2025-07-01 19:09:25 +00:00

First commit

This commit is contained in:
2019-12-15 12:10:37 +01:00
commit 8084edf5fa
8 changed files with 1015 additions and 0 deletions

BIN
tests/GeoLite2-Country.mmdb Normal file

Binary file not shown.

83
tests/nginx.conf Normal file
View File

@ -0,0 +1,83 @@
user nobody;
worker_processes auto;
timer_resolution 100ms;
error_log /dev/fd/2 notice;
pid run/nginx.pid;
events {
worker_connections 4096;
multi_accept on;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'$request_length $request_time $upstream_response_time '
'"$http_referer" "$http_user_agent" $http_x_forwarded_for';
server_tokens off;
ignore_invalid_headers on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
etag off;
client_body_timeout 30;
client_header_timeout 30;
large_client_header_buffers 4 8k;
send_timeout 30;
keepalive_timeout 30 30;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_certificate /tmp/cert.pem;
ssl_certificate_key /tmp/cert.key;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;
ssl_dhparam /tmp/dhparams.pem;
ssl_ecdh_curve secp384r1;
geoip2 /tmp/GeoLite2-Country.mmdb {
auto_reload 24h;
$geoip_country_iso_code country iso_code;
$geoip_country_name country names en;
}
# geoip2 /usr/local/nginx/conf/maxminddb/GeoLite2-City.mmdb {
# auto_reload 24h;
# $geoip_postal_code postal code;
# $geoip_latitude location latitude;
# $geoip_longitude location longitude;
# $geoip_city city names en;
# }
limit_req_zone $binary_remote_addr zone=limited4:10m rate=4r/s;
limit_req_status 429;
#######################################################
# default vhost #
#######################################################
server {
listen 80 default_server;
listen 443 http2 ssl;
server_name _ "";
access_log /dev/fd/1;
location = /geoip {
limit_req zone=limited4 burst=5 nodelay;
if ($http_user_agent ~* (?:curl|wget|libwww-perl|python|ansible-httpget|HTTPie|WindowsPowerShell|http_request|^$)) {
return 200 "$remote_addr\n";
}
}
location = /nginx_status {
stub_status on;
}
}
}

78
tests/test.sh Executable file
View File

@ -0,0 +1,78 @@
#!/usr/bin/env bash
set -e
trap _catch_err ERR
trap _cleanup EXIT
LOCAL_DIR=$(dirname "$0")
LOCAL_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
. "$LOCAL_DIR"/../conf.env
TMP_DIR=$(mktemp -d)
_catch_err()
{
echo "Test FAILED"
}
_cleanup()
{
echo "Cleaning up..."
docker rm -f "${NGINX_VERSION}"_test > /dev/null 2>&1
rm -rf "$TMP_DIR"
}
_setup_crypto_stuff()
{
openssl dhparam -out "$TMP_DIR"/dhparams.pem 512
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
-subj "/C=ES/ST=Madrid/L=Madrid/O=dcarrillo/CN=localhost" \
-keyout "$TMP_DIR"/cert.key -out "$TMP_DIR"/cert.pem
}
_check_status_code()
{
if [ "$1" != 200 ]; then
printf "Test failed, status code %s is not 200\n" "$STATUS_CODE"
exit 1
else
echo "Test succeeded"
fi
}
_check_if_is_ip()
{
if echo "$1" | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" > /dev/null; then
echo "Test succeeded"
else
printf "Test failed, response %s is not an IP" "$RESPONSE"
exit 1
fi
}
_setup_crypto_stuff
docker run --name "${NGINX_VERSION}"_test --rm -p 65521:80 -p 65523:443 \
-v "$LOCAL_DIR"/nginx.conf:/usr/local/nginx/conf/nginx.conf:ro \
-v "$LOCAL_DIR"/GeoLite2-Country.mmdb:/tmp/GeoLite2-Country.mmdb:ro \
-v "$TMP_DIR"/cert.pem:/tmp/cert.pem:ro \
-v "$TMP_DIR"/cert.key:/tmp/cert.key:ro \
-v "$TMP_DIR"/dhparams.pem:/tmp/dhparams.pem:ro \
-d "${DOCKER_IMAGE}":"${NGINX_VERSION}"
printf "\nTesting http request: %s:%s\n" "${DOCKER_IMAGE}" "${NGINX_VERSION}"
STATUS_CODE=$(curl -s -m 5 -o /dev/null -w "%{http_code}" http://localhost:65521/nginx_status)
_check_status_code "$STATUS_CODE"
printf "\nTesting https request: %s:%s\n" "${DOCKER_IMAGE}" "${NGINX_VERSION}"
STATUS_CODE=$(curl -s -m 5 -o /dev/null -w "%{http_code}" --http2 -k https://localhost:65523/)
_check_status_code "$STATUS_CODE"
printf "\nTesting http geoip request: %s:%s\n" "${DOCKER_IMAGE}" "${NGINX_VERSION}"
RESPONSE=$(curl -s -m 5 http://localhost:65521/geoip)
_check_if_is_ip "$RESPONSE"
echo "All tests succeeded !"