docker-compose 部署nginx
创建目录 创建文件 构建 你应该会看到html的index.html界面 进一步
创建目录
mkdir -p docker-compose-nginx/{html,conf,conf.d,logs}
创建文件
cat > ./html/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and working.</p>
<p>For more information, visit <a href="http://nginx.org/">nginx.org</a>.</p>
</body>
</html>
EOF
cat > ./html/error.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>An error occurred.</h1>
<p>The page you requested is currently unavailable. Please try again later.</p>
<p>If you are the administrator, check the error logs for details.</p>
</body>
</html>
EOF
cat > ./conf.d/default.conf << 'EOF'
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
EOF
cat > ./conf/nginx.conf << 'EOF'
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
EOF
cat > ./docker-compose.yml << 'EOF'
services:
nginx:
image: nginx:1.26.3
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
- ./conf.d:/etc/nginx/conf.d:ro
- ./html:/usr/share/nginx/html:ro
- ./logs:/var/log/nginx
EOF
构建
docker-compose up -d
你应该会看到html的index.html界面
进一步
docker network create default_network
原始笔记:cloud/docker-compose-nginx部署.md