将nginx部署在局域网服务器上,这样即使公网服务器换了,也只需要映射一下80端口。
局域网服务器(以下称为NAS服务器)上的系统是通过硬盘安装的omv4。也就是说,装好系统时80端口默认分配给了omv的web后台管理系统。
首先将omv4的web端迁移到其它端口。
在 /etc/nginx/sites-available/openmediavault-webgui 文件中定义了 omv4 相关的配置,直接修端口:
#listen 80;
listen 88;
然后重启默认的nginx:
systemctl daemon-reload
systemctl restart nginx
检查以下两个端口:
curl 127.0.0.1:80
curl 127.0.0.1:88
从容器中拉取配置文件:
docker run -d --name nginx -p 80:80 nginx
export DIR=/home/docker/nginx
mkdir -p $DIR
docker cp nginx:/etc/nginx/conf.d $DIR/conf.d
docker cp nginx:/etc/nginx/nginx.conf $DIR/nginx.conf
docker rm -f nginx
在 conf.d 目录下新建一个 server 配置文件 mywebs.conf:
server {
listen 80;
server_name xxx.yyy;
location / {
proxy_pass http://172.17.0.2:8090;
}
}
server {
listen 80;
server_name qbt.xxx.yyy;
location / {
proxy_pass http://172.17.0.6:6996;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name fb.xxx.yyy;
location / {
proxy_pass http://172.17.0.3:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name rr.xxx.yyy;
location / {
proxy_pass http://172.17.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
运行容器:
docker run --name nginx -p 80:80 -v /home/docker/nginx/html:/usr/share/nginx/html -v /home/docker/nginx/log:/var/log/nginx -v /home/docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/docker/nginx/conf.d:/etc/nginx/conf.d nginx
natapp 设置:
原文:https://www.cnblogs.com/barwe/p/14147520.html