docker-compose 搭建 web 环境

发布于 25 天前  41 次阅读


来不及批服务器了,直接在本地搭了一个nginx服务,造一台靶机来打

原理和之前搭建个人博客一毛一样,这里只是用php的镜像替换掉了wordpress

0x00 目录结构

├── docker-compose.yml
└── www
    ├── conf
    │   └── nginx.conf
    └── web
        └── index.php

0x01 文件内容

docker-compose.yml

version: "2.3"
services:
  nginx:
    image: nginx
    privileged: true
    ports: 
      - "80:80"
    volumes: 
      - ./www/web:/usr/share/nginx/html
      - ./www/conf:/etc/nginx/conf.d
      - ./www/logs:/var/log/nginx
    networks:
      - web-net
  php:
    image: phpdockerio/php72-fpm
    privileged: true
    volumes:
      - ./www/web:/web
    networks:
      - web-net
  mysql:
    image: mysql
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
    networks:
      - web-net
networks: 
  web-net:

www/conf/nginx.conf

server {
	listen	80;
	server_name	localhost;

	location / {
		root	/usr/share/nginx/html;
		index	index.html index.htm index.php;
	}

	error_page	500 502 503 504	/50x.html;
	location = /50x.html {
		root	/usr/share/nginx/html;
	}

	location ~ \.php$ {
		fastcgi_pass	php:9000;
		fastcgi_index	index.php;
		fastcgi_param	SCRIPT_FILENAME	/web/$fastcgi_script_name;
		include		fastcgi_params;
	}
}

www/web/index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hello</title>
</head>
<body>
    <h2>Hello World!</h2>
</body>
</html>

0x02 运行

docker-compose up -d

记得配置www/conf/nginx.conf,不然可能会遇到我之前的哈皮问题:一个nginx.conf引发的惨案

运行效果图:

然后浏览器访问 127.0.0.1

配置成功!

然后就可以在里面配置靶场环节啦


"May there be enough clouds, to make a beautiful sunset."