-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
78 additions
and
9 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 |
---|---|---|
@@ -1,47 +1,72 @@ | ||
# nginx lab | ||
|
||
Getting the image: | ||
- [Getting the image](#getting-the-image) | ||
- [Run the bare image](#run-the-bare-image) | ||
- [Configuration](#configuration) | ||
- [Proxy server](#proxy-server) | ||
- [Match request path with regex](#match-request-path-with-regex) | ||
- [Load balancing](#load-balancing) | ||
|
||
## Getting the image | ||
|
||
``` | ||
docker pull nginx | ||
``` | ||
|
||
Run the bare image: | ||
## Run the bare image | ||
|
||
``` | ||
docker run -d -p 80:80 nginx | ||
docker run --rm -d -p 80:80 nginx | ||
curl localhost | ||
``` | ||
|
||
You should get the **Welcome to nginx** web page. | ||
|
||
## Configuration | ||
|
||
Configuration directives's hierachy: | ||
- `main` context contains `events` and `http` | ||
- `http` contains `server` | ||
- `server` contains `location` | ||
|
||
|
||
Loading a minimal configuration (see `./nginx.conf` for details): | ||
``` | ||
docker run -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/data:/data:ro -p80:80 nginx | ||
docker run --rm -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/data:/data:ro -p80:80 nginx | ||
``` | ||
|
||
Then you should be able to get: | ||
- http://localhost | ||
- http://localhost/images/example.png | ||
|
||
Proxy server (see `nginx-proxy.conf`): | ||
## Proxy server | ||
|
||
See `nginx-proxy.conf`. | ||
|
||
``` | ||
docker run -v $(pwd)/nginx-proxy.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/data:/data:ro -p80:80 nginx | ||
docker run --rm -v $(pwd)/nginx-proxy.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/data:/data:ro -p80:80 nginx | ||
curl localhost | ||
``` | ||
|
||
Match request path with regex (see `nginx-regex.conf`): | ||
## Match request path with regex | ||
|
||
See `nginx-regex.conf`. | ||
|
||
``` | ||
docker run -v $(pwd)/nginx-regex.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/data:/data:ro -p80:80 nginx | ||
docker run --rm -v $(pwd)/nginx-regex.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/data:/data:ro -p80:80 nginx | ||
``` | ||
|
||
- http://localhost/example.png | ||
|
||
## Load balancing | ||
|
||
See `nginx-lb.conf`. | ||
|
||
``` | ||
docker run --rm -d -v $(pwd)/nginx-lb.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/data:/data:ro -p 80:80 nginx | ||
``` | ||
|
||
Now if you keep reading from http://localhost, it will respond with these responses in round-robin order: | ||
|
||
- hello from site 1 | ||
- hello from site 2 | ||
- hello from site 3 |
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,5 @@ | ||
<html> | ||
<body> | ||
<p>hello from site 1</p> | ||
</body> | ||
</html> |
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,5 @@ | ||
<html> | ||
<body> | ||
<p>hello from site 2</p> | ||
</body> | ||
</html> |
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,5 @@ | ||
<html> | ||
<body> | ||
<p>hello from site 3</p> | ||
</body> | ||
</html> |
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,29 @@ | ||
http { | ||
upstream myservers { | ||
server 127.0.0.1:8081; | ||
server 127.0.0.1:8082; | ||
server 127.0.0.1:8083; | ||
} | ||
|
||
server { | ||
listen 8081; | ||
root /data/site1; | ||
} | ||
|
||
server { | ||
listen 8082; | ||
root /data/site2; | ||
} | ||
|
||
server { | ||
listen 8083; | ||
root /data/site3; | ||
} | ||
|
||
server { | ||
location / { | ||
proxy_pass http://myservers/; | ||
} | ||
} | ||
} | ||
events { } |