commit 43334f4eae263517f7deb9e317a5c7abb9bab038 Author: Matthew Raymer Date: Wed Jul 10 17:19:31 2024 +0800 Initial commit diff --git a/.env~ b/.env~ new file mode 100644 index 000000000..c16878d29 --- /dev/null +++ b/.env~ @@ -0,0 +1 @@ +HAPPY_GREETING=Hello, from hackerbox.io :) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..35a52219e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3' +services: + survey-nginx: + container_name: survey-nginx + build: + context: ./survey-nginx + volumes: + - ./survey-nginx/html:/var/www + - ./survey-nginx/perl:/usr/share/perl + - ./survey-nginx/log/web:/var/log/nginx/web + ports: + - "8080:80" diff --git a/survey-nginx/Dockerfile b/survey-nginx/Dockerfile new file mode 100644 index 000000000..b5205e224 --- /dev/null +++ b/survey-nginx/Dockerfile @@ -0,0 +1,9 @@ +FROM nginx:1.27.0-alpine-perl + +RUN apk update +RUN apk add bash curl + +EXPOSE 80 + +ADD ./nginx.conf /etc/nginx/nginx.conf +RUN rm /etc/nginx/conf.d/default.conf diff --git a/survey-nginx/html/hello_world.pl b/survey-nginx/html/hello_world.pl new file mode 100755 index 000000000..bc285396e --- /dev/null +++ b/survey-nginx/html/hello_world.pl @@ -0,0 +1,3 @@ +#!/usr/bin/perl -wT +print "Content-type: text/plain\n\n"; +print "Hello World In CGI Perl" diff --git a/survey-nginx/html/index.html b/survey-nginx/html/index.html new file mode 100644 index 000000000..e8afbc608 --- /dev/null +++ b/survey-nginx/html/index.html @@ -0,0 +1,13 @@ + + + + + + + Document + + +

Hello World In html file

+ + + diff --git a/survey-nginx/log/web/access.log b/survey-nginx/log/web/access.log new file mode 100644 index 000000000..12397dbc9 --- /dev/null +++ b/survey-nginx/log/web/access.log @@ -0,0 +1,6 @@ +127.0.0.1 - - [07/Jul/2024:09:25:01 +0000] "GET /hello_world.pl HTTP/1.1" 502 28 "-" "curl/8.5.0" +127.0.0.1 - - [07/Jul/2024:09:33:52 +0000] "GET /hello_world.pl HTTP/1.1" 502 28 "-" "curl/8.5.0" +127.0.0.1 - - [07/Jul/2024:09:41:42 +0000] "GET /hello_world.pl HTTP/1.1" 502 28 "-" "curl/8.5.0" +127.0.0.1 - - [07/Jul/2024:09:47:09 +0000] "GET /hello_world.pl HTTP/1.1" 502 28 "-" "curl/8.5.0" +127.0.0.1 - - [07/Jul/2024:09:51:26 +0000] "GET /hello_world.pl HTTP/1.1" 502 28 "-" "curl/8.5.0" +127.0.0.1 - - [07/Jul/2024:09:52:58 +0000] "GET /hello_world.pl HTTP/1.1" 502 28 "-" "curl/8.5.0" diff --git a/survey-nginx/log/web/error.log b/survey-nginx/log/web/error.log new file mode 100644 index 000000000..7fae757bc --- /dev/null +++ b/survey-nginx/log/web/error.log @@ -0,0 +1,4 @@ +2024/07/07 09:41:42 [info] 9#9: *1 client 127.0.0.1 closed keepalive connection +2024/07/07 09:47:09 [info] 26#26: *1 client 127.0.0.1 closed keepalive connection +2024/07/07 09:51:26 [info] 28#28: *3 client 127.0.0.1 closed keepalive connection +2024/07/07 09:52:58 [info] 45#45: *5 client 127.0.0.1 closed keepalive connection diff --git a/survey-nginx/nginx.conf b/survey-nginx/nginx.conf new file mode 100644 index 000000000..44037bdcc --- /dev/null +++ b/survey-nginx/nginx.conf @@ -0,0 +1,34 @@ +user nginx; +worker_processes 1; +error_log /var/log/nginx/error.log debug; +pid /var/run/nginx.pid; +load_module modules/ngx_http_perl_module.so; + +events { + worker_connections 1024; +} + +http { + perl_modules /usr/lib/perl5/vendor_perl; + include /etc/nginx/mime.types; + sendfile off; + server_tokens off; + + server { + listen 80; + server_name _; + resolver 8.8.8.8; + + location / { + perl 'sub { + my $r = shift; + $r->send_http_header("text/html"); + $r->print("Hello from Perl embedded in nginx!\n"); + return OK; + }'; + } + location ~ \.pl$ { +# perl 'MyApp::handler'; # Assuming MyApp::handler is defined in a Perl module + } + } +} \ No newline at end of file diff --git a/survey-nginx/perl/MyModule.pm b/survey-nginx/perl/MyModule.pm new file mode 100644 index 000000000..d9c23f9f9 --- /dev/null +++ b/survey-nginx/perl/MyModule.pm @@ -0,0 +1,15 @@ +package MyModule; + +use nginx; # Make sure to use the nginx module + +sub handler { + my $r = shift; # Get the request object + $r->send_http_header("text/html"); # Send HTTP headers + + # Print a simple HTML page + $r->print("

Hello, Nginx Perl!

"); + + return OK; +} + +1; # Ensure the module returns true