0 版本
1 配置文件说明
1.1 容器中的配置文件目录结构
└─/
└─etc/
└─nginx/
├─conf.d/
│ └─default.conf
├─fastcgi_params
├─mime.types
├─modules
├─nginx.conf
├─scgi_params
└─uwsgi_params
1.2 nginx.conf
结构说明
全局配置;
events配置{
..
}
http配置{
http全局配置;
upstream配置{
..
}
server配置{
server全局配置;
location配置{
..
}
}
}
1.3 nginx.conf
配置文件
- 下面是容器中
nginx.conf
配置文件的内容,由include /etc/nginx/conf.d/*.conf
可以看出,我们可以将自定义配置放到/etc/nginx/conf.d/
路径中,容器会自动加载这里的配置文件
user nginx;
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;
}
- 下面是
default.conf
自定义配置的内容
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;
}
}
2 dokcer-compose启动
2.1 目录结构
- orion-web是一个项目名称,根据实际情况编写
├─nginx
│ ├─docker-compose.yml
│ ├─config
│ │ └─orion-web.conf
│ └─orion-web
│ │ └─..(静态资源)
orion-web.conf
配置文件server {
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;
}
}
2.2 配置docker-compose.yml
文件
2.3 启动
- 启动:在docker-compose.yml所在目录中执行
docker-compse up -d
- 停止并删除:
docker-compose down