码头工人nginx服务如何部署

  介绍

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

1。下载nginx
码头工人拉nginx 

2。启动nginx

码头工人运行- d - m 2 g  - p 8888:80——名字lyjng nginx

3。配置映射

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

其中:

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

4。复制码头工人容器中的文件

 [root@ambari-01  lyjnginx] #, docker  ps 
  CONTAINER  ID ,, IMAGE ,,,, COMMAND ,,,,,,,,,,,,,,,,, CREATED ,,,,,,,,, STATUS ,,,,,,,,, PORTS ,,,,,,,,,,,,,,,,,的名字
  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 /根/lyjnginx/nginx/conf/

5。部署命令

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

命令说明:

,,,,,,- m:设置容器占用内存
,,,rm:容器终止运行后,自动删除容器文件。
,,,80 - p 8889:80:将容器的端口映射到主机的8889端口。
,,,——名字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。配置:将我们自己创建的nginx。参看挂载到容器的/etc/nginx/nginx.参看。
,,,- v/root/lyjnginx/nginx/logs:/var/log/nginx:将我们自己创建的日志挂载到容器的/var/log/nginx。

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

 [root@ambari-01 相依]#,cd /根/lyjnginx/nginx/www/(root@ambari-01  www) #, vim  index . html
  
  & lt; ! DOCTYPE  html>
  & lt; html>
  & lt; head>
  & lt; meta  charset=皍tf-8"祝辞
  & lt; title> Nginx  test  ! ! ! & lt;/title>
  & lt;/head>
  & lt; body>
  ,,,& lt; h2>我的第一个标题& lt;/h2>
  ,,,& lt; p>我的第一个段落。;/p>
  & lt;/body>
  & lt;/html> 

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

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

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

 user , nginx;
  worker_processes , 1;
  
  error_log ,/var/log/nginx/error.log 警告;
  pid ,,,,,,,/var/运行/nginx.pid;
  
  
  events  {
  ,,,worker_connections , 1024;
  }
  
  
  http  {
  ,,,include ,,,,,,/etc/nginx/mime.types;
  ,,,default_type ,应用程序/八进制;
  
  ,,,log_format , main , & # 39; remote_addr 美元;作用;remote_user 美元;[time_local美元],“request"美元;,& # 39;
  ,,,,,,,,,,,,,,,,,,,,,& # 39;status 美元;body_bytes_sent 美元;“http_referer"美元;,& # 39;
  ,,,,,,,,,,,,,,,,,,,,,& # 39;“http_user_agent"美元;,“http_x_forwarded_for"美元;& # 39;;
  
  ,,,access_log ,/var/log/nginx/access.log ,主要;
  
  ,,,sendfile ,,,,,,,,
  ,,,# tcp_nopush ,,,,,
  
  ,,,keepalive_timeout , 65;
  
  ,,,# gzip ,;
  ,,#,这行必须注释否则/etc/nginx/conf.d/* .conf 会覆盖下面服务器{}中的配置
  ,,#,include /etc/nginx/conf.d/* . conf;
  ,,# lyj 添加
  ,,,,server  {
  ,,,,,,,,,listen ,,,,,, 80;
  ,,,,,,,,,server_name ,本地主机;
  ,,
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null

码头工人nginx服务如何部署