使用docker映射多个前端容器到服务器的80端口
更新apt索引
sudo apt-get update
安装Docker
sudo apt-get install docker.io
创建Docker网络
启动前端服务容器
配置反向代理
安装Nginx
sudo apt-get install nginx
接着,创建一个Nginx配置文件,例如/etc/nginx/sites-available/myproject,来配置反向代理:
server{
listen 80;
location /app1{
proxy_pass http://app1:80; #转发到app1容器
}
location /app2{
proxy_pass http://app2:80; #转发到app1容器
}
}
将配置文件链接到site-enabled目录并重启Nginx:
链接配置文件到sites-enabled
sudo ln -s /etc/nginx/site-available/myproject /etc/nginx/sites-enabled/
检查Nginx配置是否正确
sudo nginx -t
重启Nginx
sudo systemctl restart nginx