docker安装nginx
原始地址:https://www.runoob.com/docker/docker-install-nginx.html
1、安装nginx,docker运行一个容器后,将主机中当前目录下的文件夹挂载到容器的文件夹后
进入到docker容器内对应的挂载目录中,运行命令ls后提示:
ls: cannot open directory .: Permission denied
解决:
在docker run一个容器时,加上
--privileged=true
给容器加特权即可。

2、最终命令:
docker run -d -p 8082:80 --name nginx-test-web --privileged=true -v ~/nginx/www:/usr/share/nginx/html -v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/nginx/logs:/var/log/nginx nginx
3、

4、nginx.conf配置
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; 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; #tcp_nopush on; keepalive_timeout 65; #gzip on; upstream taskA_servers{ server 192.168.220.114:8090 weight=1; #1号服务器A任务端口 server 192.168.220.114:5003 weight=1; #2号服务器A任务端口 } server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } location /a/ { proxy_pass http://taskA_servers/; } } }

浙公网安备 33010602011771号