1悼潭、創(chuàng)建映射目錄
mkdir -p /docker/nginx/{conf,conf.d,www,log,html,letsencrypt,cert}
2潮酒、創(chuàng)建網(wǎng)絡(luò)壞境
docker network create --driver=bridge --subnet=192.168.88.0/24? cidi
3、創(chuàng)建docker-compose.yml
cat > /docker/nginx/docker-compose.yml << EOF
version: "3"
services:
? nginx:
? ? image: nginx:latest
? ? container_name: nginx
? ? restart: always
? ? ports:
? ? ? - "80:80"
? ? ? - "433:433"
? ? volumes:
? ? ? - /docker/nginx/conf:/etc/nginx/conf
? ? ? - /docker/nginx/conf.d:/etc/nginx/conf.d
? ? ? - /docker/nginx/log:/var/log/nginx
? ? ? - /docker/nginx/www:/var/www
? ? ? - /docker/nginx/letsencrypt:/etc/letsencrypt
? ? ? - /docker/nginx/html:/usr/share/nginx/html
? ? ? - /docker/nginx/cert:/etc/nginx/cert
? ? networks:
? ? ? - cidi
? ? ? ? #ipv4_address: 192.169.0.3
networks:
? cidi:
? ? external: true
? ? ? #driver: bridge
? ? ? #ipam:
? ? ? ? #config:
? ? ? ? ? ? #- subnet: 10.10.0.0/16
EOF
4磨镶、 配置nginx 主配置
cat >? /docker/nginx/conf/nginx.conf << EOF
user? nginx;
worker_processes? 1;
error_log? /var/log/nginx/error.log warn;
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;
? ? #tcp_nopush? ? on;
? ? keepalive_timeout? 65;
? ? #gzip? on;
? ? include /etc/nginx/conf.d/*.conf;
}
EOF
5枷遂、默認(rèn)配置設(shè)置
cat > /docker/nginx/conf.d/default.conf << EOF
server {
? ? listen? ? ? 80;
? ? #server_name? localhost;
? ? #charset koi8-r;
? ? #access_log? /var/log/nginx/log/host.access.log? main;
? ? location / {
? ? ? ? root? /var/www;
? ? ? ? index? index.html index.htm;
? ? ? ? autoindex? on;
? ? }
? ? location /jenkins {
? ? ? ? ? ? proxy_pass http://jenkins:8080/jenkins;
? ? ? ? ? ? #proxy_set_header Host $host;
? ? ? ? ? ? #proxy_set_header X-Real-IP $remote_addr;
? ? ? ? ? ? #proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
? ? ? ? }
? ? #error_page? 404? ? ? ? ? ? ? /404.html;
? ? # redirect server error pages to the static page /50x.html
? ? #
? ? error_page? 500 502 503 504? /50x.html;
? ? location = /50x.html {
? ? ? ? root? /usr/share/nginx/html;
? ? }
? ? # proxy the PHP scripts to Apache listening on 127.0.0.1:80
? ? #
? ? #location ~ \.php$ {
? ? #? ? proxy_pass? http://127.0.0.1;
? ? #}
? ? # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
? ? #
? ? #location ~ \.php$ {
? ? #? ? root? ? ? ? ? html;
? ? #? ? fastcgi_pass? 127.0.0.1:9000;
? ? #? ? fastcgi_index? index.php;
? ? #? ? fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
? ? #? ? include? ? ? ? fastcgi_params;
? ? #}
? ? # deny access to .htaccess files, if Apache's document root
? ? # concurs with nginx's one
? ? #
? ? #location ~ /\.ht {
? ? #? ? deny? all;
? ? #}
}
EOF
6、運行?
docker-compose up -d
7棋嘲、測試,測試404的話矩桂,需要在自己創(chuàng)建的www文件夾增加index.html
curl localhost??