概述
使用 Docker 安装和与运行 Nginx,docker-compose.yml
配置如下:
version: '3.1'
services:nginx:restart: alwaysimage: nginxcontainer_name: nginxports:- 80:80volumes:- ./conf/nginx.conf:/etc/nginx/nginx.conf- ./wwwroot:/usr/share/nginx/wwwroot
基于端口的虚拟主机
配置虚拟主机
worker_processes 1;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;# 配置虚拟主机 192.168.106.128server {# 监听的ip和端口,配置 192.168.106.128:80listen 80;# 虚拟主机名称这里配置ip地址server_name 192.168.106.128;# 所有的请求都以 / 开始,所有的请求都可以匹配此 locationlocation / {# 使用 root 指令指定虚拟主机目录即网页存放目录# 比如访问 http://ip/index.html 将找到 /usr/local/docker/nginx/wwwroot/html80/index.html# 比如访问 http://ip/item/index.html 将找到 /usr/local/docker/nginx/wwwroot/html80/item/index.htmlroot /usr/share/nginx/wwwroot/html80;# 指定欢迎页面,按从左到右顺序查找index index.html index.htm;}}# 配置虚拟主机 192.168.106.128server {listen 8080;server_name 192.168.106.128;location / {root /usr/share/nginx/wwwroot/html8080;index index.html index.htm;}}
}
基于域名的虚拟主机配置
配置虚拟主机
user nginx;
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 admin.service.itoken.yuu.com;location / {root /usr/share/nginx/wwwroot/htmlservice;index index.html index.htm;}}server {listen 80;server_name admin.web.itoken.yuu.com;location / {root /usr/share/nginx/wwwroot/htmlweb;index index.html index.htm;}}
}