docker安装nginx
我这里使用的是nginx1.25.3
拉取nginx的版本镜像:docker pull nginx:1.25.3
拉取完成之后,在主机上创建nginx.conf的配置文件,比如
mkdir /home/xxx/nginx
mkdir /home/xxx/project
cd /home/xxx/nginx
vim nginx.conf 文件的内容形式如下:
#user nobody;
user root;
worker_processes 8;
events {
worker_connections 102400;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8000;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /es{
alias /home/xxx/project;
index index.html;
}
#linux的配置
location /esdddd{
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_pass http://localhost:90900/aaa;
proxy_read_timeout 300;
}
}
}
创建容器
docker run --name nginx-test -p 9000:8000 -v /home/xxx/project:/home/xxx/project -v /home/xxx/nginx/nginx.conf:/etc/nginx/nginx.conf -d nginx:1.25.3
容器在安装之后,如果时区有问题,可以使用下面的方式,将宿主机的拷贝过去
docker cp /usr/share/zoneinfo/Asia/Shanghai 容器id:/etc/localtime
