1, the use of docker-compose mounting
1. Create a folder as the host docker container associated files
cd /usr/local
mkdir docker
cd docker
mkdir nginx
cd nginx
2, create the corresponding docker-compose.yml and write the following contents: vim docker-compose.yml
version: '3.1'
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./www:/usr/share/nginx/www
2, create the necessary files based on the contents of docker-compose.yml
1, two folders
mkdir conf
mkdir www
2, create a configuration file nginx nginx.conf
cd conf
vim nginx.conf
3, is written in the configuration file following
# 启动多少个进程
worker_processes 1;
events {
# 每个进程的最大并发数
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 配置一个服务
server {
# 监听的端口
listen 80;
# 虚拟主机名称(一般为域名)
server_name hwq.nginx.com;
# 配置资源的本地路径,以及缺省路由自动默认响应文件
location / {
root /usr/share/nginx/www/html80;
index index.html index.htm;
}
}
}
3, create a static html file in the local host configuration files according to the above, as a test
1, create the appropriate folders and files
cd /usr/local/docker/nginx/www/
mkdir html80
cd html80
vim index.html
2, writes the following
<html lang="zh">
<head>
<meta charset="utf-8">
</head>
<body>
<h1>欢迎访问 nginx</h1>
</body>
</html>
3, modify the host file system to access the server's windows, the address is: C: \ Windows \ System32 \ drivers \ etc \ host, add the following
192.168.200.100 hwq.nginx.com
Ps 192.168.200.100 address for the virtual machine