docker中如何使用nginx(docker nginx实现一个主机部署多个站点操作)
docker中如何使用nginx
docker nginx实现一个主机部署多个站点操作在某站租赁的虚拟机快到期了,续费得花200多,想到在阿里云新买的服务器,不如把这个也转移过去。域名我就用真实的吧,大家别黑我网站就好了,谢谢各位了。
阿里云里面已经用部署了一个站点 用域名 www.dcssn.com 就能直接访问,我的想法是再用 www.xhxf119.com 指向这个主机,根据域名的不同去访问不同的服务。
首先
域名解析都要指向这个主机的ip
然后
www.dcssn.com的服务开启8080端口,docker run -p 8080:80 weian
www.xhxf119.com的服务开启8081端口,docker run -p 8081:80 xinhua
用www.dcssn.com:8080 能正常访问 www.xhxf119.com:8081也能正常访问
接下来 写nginx的配置文件
nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.dcssn.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://47.92.69.112:8080; } } server { listen 80; server_name www.xhxf119.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://47.92.69.112:8081; } } }
然后把这个文件保存到/host/path/ 目录下
docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d -p 80:80 nginx
大概流程就是这样了 就可以直接输入 www.dcssn.com 或者 www.xhxf119.com 访问了
补充知识:docker配置nginx支持多个子域名对应不同的项目目录
有机会要弄一个反向代理分发
具体的php与nginx配置请看本人博客里的搭建
cd /root/nginx/conf/conf.d
vim runoob-test-php.conf
runoob-test-php.conf文件内容,其实就是子域名对应目录就行
server { listen 80; server_name www.liuyuanshan.top; location / { #proxy_pass http://106.52.36.65:80; root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name message.liuyuanshan.top; location / { root /usr/share/nginx/html/message/; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/message/$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name wordpress.liuyuanshan.top; location / { root /usr/share/nginx/html/wordpress/; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress/$fastcgi_script_name; include fastcgi_params; } }
重启docker的nginx容器
docker restart ngixn
以上这篇docker nginx实现一个主机部署多个站点操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持开心学习网。
- docker容器使用redis服务(在Docker中使用Redis的步骤详解)
- docker怎样安装mysql8(docker-compose安装db2数据库操作)
- dockerfile配置参数(dockerfile中ENTRYPOINT与CMD的结合使用及区别)
- docker安装nginx如何配置(docker部署nginx并且挂载文件夹和文件操作)
- docker服务重启容器是否重启(docker自定义网桥docker0及docker的开启,关闭,重启命令操作)
- docker swarm管理(Docker Swarm 服务编排之命令详解)
- docker怎么装mongodb(Docker 搭建集群MongoDB的实现步骤)
- docker容器内服务怎么启动(docker部署confluence的完整步骤)
- docker原理和使用方法(docker的一些基本指令)
- dockerfile映射目录(Dockerfile中ENTRYPOINT 和 CMD的区别说明)
- docker容器管理技巧(Docker容器编排实现过程解析)
- docker显示出错应用图标怎么处理(docker 命令报异常permission denied的解决方案)
- docker集群安装教程(使用docker部署hadoop集群的详细教程)
- docker挂载的注意事项(解决docker日志挂载的问题)
- docker快速配置redis集群(基于docker搭建redis集群的方法)
- docker 镜像id修改(Docker Alpine镜像时区问题完美解决方案)
- 远离 五毛食品 洛阳80后妈妈发明的 飞行棋 成校园爆款 玩具(远离五毛食品)
- 失传的古代飞行棋游戏 六博(失传的古代飞行棋游戏)
- 感冒要吃什么药(猫咪感冒要吃什么药)
- 下雪会怎样(下雪怎样画)
- 白蓝色穿搭(白蓝色衣服配什么裤子)
- 天空是什么颜色(天空是什么颜色的英语)
热门推荐
- thinkphp5 新增模块(Thinkphp5.0框架的Db操作实例分析连接、增删改查、链式操作等)
- 如何提高移动网站的用户体验
- mysql编码设置
- linuxnginx常用状态命令(nginx常用命令放入shell脚本详解)
- JavaScript命名空间
- 宝塔面板服务器设置(使用宝塔面板做负载均衡时遇到的问题和解决办法)
- mysql的count知识(MySQL中MTR的概念)
- SQL SERVER中调用存储过程
- 树莓派3B+安装64位ubuntu系统和docker工具的操作步骤详解(树莓派3B+安装64位ubuntu系统和docker工具的操作步骤详解)
- css媒体查询常见的媒体类型(css基于媒体查询和 rem 的响应式布局实践)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9