try Nginx
client -> nginx -> httpd
apache httpd
docker images
[root@vm01 work_a]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx 1.17.8 2073e0bcb60e 2 weeks ago 127MB httpd 2.4.41 c562eeace183 2 weeks ago 165MB hello-world latest fce289e99eb9 13 months ago 1.84kB [root@vm01 work_a]#
index.html (sample)
[root@vm01 work_a]# cat index.html <!DOCTYPE html> <html> <head> <title>test title</title> </head> <body> <h1>Header</h1> <p>This is test message.</p> </body> </html> [root@vm01 work_a]#
docker run for httpd
[root@vm01 work_a]# ls -l total 4 -rw-r--r-- 1 root root 139 Feb 18 12:00 index.html [root@vm01 work_a]# [root@vm01 work_a]# docker run -dit --name my-a -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4.41 78b09dbbfafc21c5eb40e4ba25797735fa93f6e9fb6b175b6013c0a8fd468478 [root@vm01 work_a]# [root@vm01 work_a]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 78b09dbbfafc httpd:2.4.41 "httpd-foreground" 4 seconds ago Up 3 seconds 80/tcp my-a [root@vm01 work_a]# [root@vm01 work_a]# docker inspect --format '{{ .NetworkSettings.IPAddress }}' my-a 172.17.0.2 [root@vm01 work_a]#
check to send request
[root@vm01 work_a]# curl -v http://172.17.0.2/ * About to connect() to 172.17.0.2 port 80 (#0) * Trying 172.17.0.2... * Connected to 172.17.0.2 (172.17.0.2) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: 172.17.0.2 > Accept: */* > < HTTP/1.1 200 OK < Date: Tue, 18 Feb 2020 03:09:08 GMT < Server: Apache/2.4.41 (Unix) < Last-Modified: Tue, 18 Feb 2020 03:00:51 GMT < ETag: "8b-59ed0e1267770" < Accept-Ranges: bytes < Content-Length: 139 < Content-Type: text/html < <!DOCTYPE html> <html> <head> <title>test title</title> </head> <body> <h1>Header</h1> <p>This is test message.</p> </body> </html> * Connection #0 to host 172.17.0.2 left intact [root@vm01 work_a]#
basic config
config for nginx
[root@vm01 work_n]# ls -l total 4 -rw-r--r-- 1 root root 775 Feb 18 11:35 nginx.conf [root@vm01 work_n]#
[root@vm01 work_n]# cat nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; 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" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' 'response_context "$sent_http_content_type" ' 'etag "$sent_http_etag" '; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; # include /etc/nginx/conf.d/*.conf; server { listen 80; location /apache/ { proxy_pass http://my-a/; } } } [root@vm01 work_n]#
run nginx container
[root@vm01 work_n]# docker run --rm --name my-n -v /root/work_n/nginx.conf:/etc/nginx/nginx.conf:ro -it --link my-a nginx:1.17.8
check request
I got httpd response via nginx(reverse proxy).
[root@vm01 work_n]# curl -v http://172.17.0.3/apache/index.html * About to connect() to 172.17.0.3 port 80 (#0) * Trying 172.17.0.3... * Connected to 172.17.0.3 (172.17.0.3) port 80 (#0) > GET /apache/index.html HTTP/1.1 > User-Agent: curl/7.29.0 > Host: 172.17.0.3 > Accept: */* > < HTTP/1.1 200 OK < Server: nginx/1.17.8 < Date: Tue, 18 Feb 2020 03:42:45 GMT < Content-Type: text/html < Content-Length: 139 < Connection: keep-alive < Last-Modified: Tue, 18 Feb 2020 03:00:51 GMT < ETag: "8b-59ed0e1267770" < Accept-Ranges: bytes < <!DOCTYPE html> <html> <head> <title>test title</title> </head> <body> <h1>Header</h1> <p>This is test message.</p> </body> </html> * Connection #0 to host 172.17.0.3 left intact [root@vm01 work_n]#
get access log
[root@vm01 work_n]# docker run --rm --name my-n -v /root/work_n/nginx.conf:/etc/nginx/nginx.conf:ro -it --link my-a nginx:1.17.8 172.17.0.1 - - [18/Feb/2020:03:42:45 +0000] "GET /apache/index.html HTTP/1.1" 200 139 "-" "curl/7.29.0" "-"response_context "text/html" etag "\x228b-59ed0e1267770\x22"
sample case 2
config
[root@vm01 work_n]# cat nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; 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" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' 'response_context "$sent_http_content_type" ' 'etag "$sent_http_etag" '; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; #include /etc/nginx/conf.d/*.conf; server { listen 80; location /apache/ { proxy_pass http://my-a/; set $debug_msg $sent_http_etag; add_header X-debug-message "this is debug message for /apache/"; } } } [root@vm01 work_n]#
request
after docker run, I sent request.
[root@vm01 work_n]# curl -v http://172.17.0.3/apache/index.html * About to connect() to 172.17.0.3 port 80 (#0) * Trying 172.17.0.3... * Connected to 172.17.0.3 (172.17.0.3) port 80 (#0) > GET /apache/index.html HTTP/1.1 > User-Agent: curl/7.29.0 > Host: 172.17.0.3 > Accept: */* > < HTTP/1.1 200 OK < Server: nginx/1.17.8 < Date: Tue, 18 Feb 2020 03:56:14 GMT < Content-Type: text/html < Content-Length: 139 < Connection: keep-alive < Last-Modified: Tue, 18 Feb 2020 03:00:51 GMT < ETag: "8b-59ed0e1267770" < Accept-Ranges: bytes < X-debug-message: this is debug message for /apache/ < <!DOCTYPE html> <html> <head> <title>test title</title> </head> <body> <h1>Header</h1> <p>This is test message.</p> </body> </html> * Connection #0 to host 172.17.0.3 left intact [root@vm01 work_n]#
log
The "etag" value is empty("-") as follows:
[root@vm01 work_n]# docker run --rm --name my-n -v /root/work_n/nginx.conf:/etc/nginx/nginx.conf:ro -it --link my-a nginx:1.17.8 172.17.0.1 - - [18/Feb/2020:03:56:14 +0000] "GET /apache/index.html HTTP/1.1" 200 139 "-" "curl/7.29.0" "-"response_context "text/html" etag "-"
sample case 3
config
[root@vm01 work_n]# cat nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; 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" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' 'response_context "$sent_http_content_type" ' 'etag "$sent_http_etag" '; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; #include /etc/nginx/conf.d/*.conf; map $sent_http_etag $debug_msg { default $sent_http_etag; } server { listen 80; location /apache/ { proxy_pass http://my-a/; add_header X-debug-message "this is debug message for /apache/ $debug_msg"; } } } [root@vm01 work_n]#
docker run & send request & check response
[root@vm01 work_n]# docker run --rm --name my-n -v /root/work_n/nginx.conf:/etc/nginx/nginx.conf:ro -it --link my-a nginx:1.17.8 172.17.0.1 - - [18/Feb/2020:04:15:07 +0000] "GET /apache/index.html HTTP/1.1" 200 139 "-" "curl/7.29.0" "-"response_context "text/html" etag "\x228b-59ed0e1267770\x22"
I got "debug_msg" from "$sent_http_etag" var.
[root@vm01 work_n]# curl -v http://172.17.0.3/apache/index.html * About to connect() to 172.17.0.3 port 80 (#0) * Trying 172.17.0.3... * Connected to 172.17.0.3 (172.17.0.3) port 80 (#0) > GET /apache/index.html HTTP/1.1 > User-Agent: curl/7.29.0 > Host: 172.17.0.3 > Accept: */* > < HTTP/1.1 200 OK < Server: nginx/1.17.8 < Date: Tue, 18 Feb 2020 04:15:07 GMT < Content-Type: text/html < Content-Length: 139 < Connection: keep-alive < Last-Modified: Tue, 18 Feb 2020 03:00:51 GMT < ETag: "8b-59ed0e1267770" < Accept-Ranges: bytes < X-debug-message: this is debug message for /apache/ "8b-59ed0e1267770" < <!DOCTYPE html> <html> <head> <title>test title</title> </head> <body> <h1>Header</h1> <p>This is test message.</p> </body> </html> * Connection #0 to host 172.17.0.3 left intact [root@vm01 work_n]#