docker nginx 配置

原博主博客链接:
Docker&Nginx-安装与配置 - 微笑刺客D - 博客园 (cnblogs.com)

1
.在虚拟机创建要需要挂载容器的文件夹 mkdir -p /docker/nginx mkdir -p /docker/nginx/conf mkdir -p /docker/nginx/www mkdir -p /docker/nginx/logs 2.创建一个nginx容器 docker run --name nginxweb -p 80:80 -d nginx 3.拷贝相关配置文件到虚拟机上 docker cp nginxweb:/etc/nginx/nginx.conf /docker/nginx docker cp nginxweb:/etc/nginx/conf.d /docker/nginx/conf docker cp nginxweb:/usr/share/nginx/html /docker/nginx/www docker cp nginxweb:/var/log/nginx /docker/nginx/logs 4.删除用来拷贝配置文件的nginx容器 docker stop nginxweb docker rm nginxweb 5.创建容器并挂载目录 docker run \ --name nginxweb \ -p 80:80 \ -v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf \ -v /docker/nginx/conf/conf.d:/etc/nginx/conf.d \ -v /docker/nginx/www:/usr/share/nginx \ -v /docker/nginx/logs:/var/log \ -d \ nginx 6.找到nginx.conf文件,修改相关配置 以下是我的nginx配置文件
=================================================================== #user nobody; worker_processes
1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; server { listen 80; # 当前server匹配使用api.gmall.com域名访问nginx的请求 server_name api.gmall.com; location / { proxy_pass http://192.168.23.104:8888; proxy_connect_timeout 20; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; # 当前server匹配使用manager.gmall.com域名访问nginx的请求 server_name manager.gmall.com; location / { proxy_pass http://192.168.23.104:1000; proxy_connect_timeout 20; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
===================================================================
7.重启容器 docker restart nginxweb

 

posted @ 2023-02-12 13:27  不想被举的栗子  阅读(917)  评论(0编辑  收藏  举报