nginx Docker

Nginx (pronounced “engine-x”) is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage.

mkdir logs cert
docker cp nginx:/usr/share/nginx/html .
docker cp nginx:/etc/nginx/nginx.conf .
docker cp nginx:/etc/nginx/conf.d .

Docker

docker run --name nginx -d nginx:stable
docker run --name nginx -d nginx:1.18

Docker Compose

nginx.yml

http://localhost/

Tests

分别用 http://127.0.0.1/proxy/index.html 进行访问

location /proxy/ {
    proxy_pass http://127.0.0.1/;
}

代理到URL:http://127.0.0.1/index.html

location /proxy/ {
    proxy_pass http://127.0.0.1;
}

代理到URL:http://127.0.0.1/proxy/index.html

location /proxy/ {
    proxy_pass http://127.0.0.1/abc/;
}

代理到URL:http://127.0.0.1/abc/index.html

location /proxy/ {
    proxy_pass http://127.0.0.1/abc;
}

代理到URL:http://127.0.0.1/abcindex.html

References