跳到主要内容

单节点部署

2024年07月09日
柏拉文
越努力,越幸运

一、认识


二、目录


├── conf/
│ └── nginx.conf
├── logs/
├── www/
│ ├── index.html
└── docker-compose.yml

三、conf


3.1 nginx.conf

events {}

http {
server {
listen 80 default_server;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

# 代理服务
# location /api {
# proxy_pass http://localhost:3000;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
}
}

四、www


4.1 index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nginx 服务</title>
</head>
<body>
<h1>欢迎来到 Nginx 服务</h1>
</body>
</html>

五、docker-compose.yml


services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- 9091:80
volumes:
- ./www:/usr/share/nginx/html
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./logs:/var/log/nginx
networks:
- nginx-network

networks:
nginx-network:
driver: bridge