目标::::我们要实现下访问Nginx的时候,代理请求tomcat服务器;
1.启动nginx
[root@localhost ~]# docker run -it --name=myNginx -v /home/data:/etc/nginx -p 80:80 nginx
或者是查看之前启动的镜像进行直接启动
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 57e59b844c41 nginx "nginx -g 'daemon of…" 23 minutes ago Exited (0) 22 minutes ago myNginx 7549a1306c9f nginx "nginx -g 'daemon of…" 45 minutes ago Exited (0) 26 minutes ago elegant_dhawan [root@localhost ~]# docker start myNginx myNginx [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 57e59b844c41 nginx "nginx -g 'daemon of…" 24 minutes ago Up 1 second 0.0.0.0:80->80/tcp myNginx
访问nginx
2.启动tomcat
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE heidaodageshiwo/jenkins0_mjg lts 5fc78c796d8c 10 days ago 594MB nginx latest 602e111c06b6 2 weeks ago 127MB openjdk latest 0ce6496aae74 3 weeks ago 497MB tomcat 8.0.52 b4b762737ed4 22 months ago 356MB [root@localhost ~]# docker run -d --name tomcat -p 8081:8080 b4b762737ed4 73ac0c2622938fe086bc2a6a8bb256571fd554bad4c3c107838842d567db6399 [root@localhost ~]#
访问tomcat
3.nginx配置
这一步很重要:::::::::::::::::::::::::::::::::::::::::::
开发80 8081端口并重启防火墙:这个步骤不弄的话访问不到。我表示弄了一周,才找到这个问题。
firewall-cmd --add-port=8081/tcp --permanent firewall-cmd --add-port=80/tcp --permanent systemctl restart firewalld.service
查看开放的端口:
[root@localhost ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: dhcpv6-client ssh ports: 8081/tcp 80/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
这一步很重要:::::::::::::::::::::::::::::::::::::::::::
这一步很重要:::::::::::::::::::::::::::::::::::::::::::
配置:
下的:
server { listen 80; server_name localhost; location / { proxy_pass http://192.168.101.13:8081/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
本机修改hosts可以搞个域名映射本机
C:\Windows\System32\drivers\etc
#nginx反向代理测试
192.168.101.13 www.zhangqiang.com
重启nginx:
1.使用tomcat的地址访问:
2.使用nginx的地址访问:
3.使用映射域名的访问:
原文链接:https://blog.csdn.net/hunheidaode/article/details/106042853
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END