docker nginx服务如何部署

35次阅读
没有评论

共计 2808 个字符,预计需要花费 8 分钟才能阅读完成。

这篇文章主要讲解了“docker nginx 服务如何部署”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着丸趣 TV 小编的思路慢慢深入,一起来研究和学习“docker nginx 服务如何部署”吧!

1. 下载 nginx
docker pull nginx 

2. 启动 nginx

docker run -d -m 2g -p 8888:80 –name lyjng nginx

3. 配置映射

创建目录: mkdir -p  /root/lyjnginx/nginx/www /root/lyjnginx/nginx/logs /root/lyjnginx/nginx/conf

其中:

      www: 目录将映射为 nginx 容器配置的虚拟目录。
      logs: 目录将映射为 nginx 容器的日志目录。
      conf: 目录里的配置文件将映射为 nginx 容器的配置文件。

4. 复制 docker 容器中的文件

[root@ambari-01 lyjnginx]# docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf7da4042664 nginx  /docker-entrypoint.…  20 minutes ago Up 20 minutes 0.0.0.0:8888- 80/tcp lyjng
[root@ambari-01 lyjnginx]# docker cp cf7da4042664:/etc/nginx/nginx.conf /root/lyjnginx/nginx/conf/

5. 部署命令

docker run -m 2g --rm -d -p 8889:80 --name nginx-test-web -v /root/lyjnginx/nginx/www:/usr/share/nginx/html -v /root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/lyjnginx/nginx/logs:/var/log/nginx nginx

命令说明:

   -m : 设置容器占用内存
      –rm:容器终止运行后,自动删除容器文件。
      -p 8889:80:将容器的 80 端口映射到主机的 8889 端口.
      –name nginx-test-web:将容器命名为 nginx-test-web 
      -v /root/lyjnginx/nginx/www:/usr/share/nginx/html:将我们自己创建的 www 目录挂载到容器的 /usr/share/nginx/html。
      -v /root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:将我们自己创建的 nginx.conf 挂载到容器的 /etc/nginx/nginx.conf。
      -v /root/lyjnginx/nginx/logs:/var/log/nginx:将我们自己创建的 logs 挂载到容器的 /var/log/nginx。

6. 添加网页 将 vue 打包的文件复制到 /root/lyjnginx/nginx/www/ 这个目录下就能访问了

[root@ambari-01 conf]# cd /root/lyjnginx/nginx/www/
[root@ambari-01 www]# vim index.html
 !DOCTYPE html 
 html 
 head 
 meta charset= utf-8 
 title Nginx test !!! /title 
 /head 
 body 
  h2 我的第一个标题 /h2 
  p 我的第一个段落。/p 
 /body 
 /html

7. 问题 nginx 代理转发一致报 404 不生效问题

vim  /root/lyjnginx/nginx/conf/nginx.conf 这个配置文件注释掉# include /etc/nginx/conf.d/*.conf;

# 这行必须注释否则 /etc/nginx/conf.d/*.conf 会覆盖下面 server{} 中的配置
   # include /etc/nginx/conf.d/*.conf;

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

 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;  #  这行必须注释否则 /etc/nginx/conf.d/*.conf  会覆盖下面 server{} 中的配置  # include /etc/nginx/conf.d/*.conf;  #lyj add  server {  listen 80;  server_name localhost;    location / {  # root /root/lyjnginx/bigdata_product;  root /usr/share/nginx/html;  index index.html index.htm;  }  location /prod-api/ {  proxy_pass http://192.168.3.175:8002/;  }  location /prod-api-extract/ {  proxy_pass http://192.168.1.134:8003/;  }  location /prod-api-dataxJ/ {  proxy_pass http://192.168.3.173:8008/;  }  location /prod-api-datax/ {  proxy_pass http://192.168.1.134:9527/;  }  }  #lyj add }

感谢各位的阅读,以上就是“docker nginx 服务如何部署”的内容了,经过本文的学习后,相信大家对 docker nginx 服务如何部署这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是丸趣 TV,丸趣 TV 小编将为大家推送更多相关知识点的文章,欢迎关注!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计2808字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)