Docker里Nginx的搭建和反向代理
安装Docker请看上一篇博客
https://blog.csdn.net/lengyer/article/details/111868424
环境
机器A:192.168.163.180(RHEL8)
机器B:192.168.163.183(Ubuntu18.04)
机器B:
Docker拉取Nginx的镜像
docker pull nginx
Docker运行Nginx
docker run --name nginx -p 80:80 -d nginx
查看Nginx是否运行
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
25b4818bfa98 nginx_v2 "/docker-entrypoint.…" 44 minutes ago Up 14 minutes 0.0.0.0:80->80/tcp nginx
curl 127.0.0.1
进到容器里
docker exec -it nginx /bin/bash
修改配置文件
cd /etc/nginx/conf.d
vim default.conf
server {
listen 80; (监听端口)
listen [::]:80;
server_name 192.168.163.183; (本机地址)
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://192.168.163.180; (反向代理)
}
}
修改网页
vim /usr/share/nginx/html/index.html
随便改点东西
重启nginx
nginx -t
nginx -s reload