為了之後學習與測試方便,我們先利用Docker來建立一個Nginx測試環境吧!
檔案結構:
docker-compose.yaml
nginx/
├─ log/
├─ html/
│ ├─ index.html
├─ default.conf
docker-compose.yaml:
version: '3'
services:
nginx:
image: nginx
container_name: my-nginx
volumes:
#- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/html:/usr/share/nginx/html
- ./nginx/log:/var/log/nginx
ports:
- "80:80"
environment:
- NGINX_PORT=80
restart: always
networks:
- mylab
networks:
mylab:
driver: bridge
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<h1>Wellcome</h1>
</body>
</html>
default.conf:
server {
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
接著執行 docker-compose up
就能跑起一個內有運行Nginx的容器,可以透過連8080 port連接到裡面的Nginx
試著在瀏覽器輸入 localhost:8080 (若容器不是跑在local,請把localhost代換成跑容器機器的ip)
應該就能看到上面寫的 index.html 網頁了 (其實就只是一個寫了Wellcome的頁面)
沒有留言:
張貼留言