问题描述
因为服务器原先已经安装了nginx(非容器安装),并且占用80端口;
而我方习惯使用容器进行安装应用,故用安装了一个容器ngixn;
docker-compose.yml
version: '3'
services:
nginx:
restart: always
container_name: nginx
image: nginx
ports:
- 81:80
- 443:443
volumes:
- /data/nginx/html:/usr/share/nginx/html
- /data/nginx/logs:/var/log/nginx
- /data/nginx/nginx.conf/:/etc/nginx/nginx.conf
- /data/nginx/etc/cert:/etc/nginx/cert
- /data/nginx/conf.d:/etc/nginx/conf.d
environment:
- TZ=Asia/Shanghai
privileged: true
default.conf
server{
listen 80;
server_name localhost;
charset utf-8;
location /test {
root /usr/share/nginx/html;
index index.html index.htm;
}
location / {
root /usr/share/nginx/html;
index ./bdcloud/index.html ./bdcloud/index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
此时我的前端服务应该都从81进入,然后交由nginx的80端口进行处理;
但此时发现在前端的登录页面总是会自动跳转到80端口,导致无法通过81端口进入nginx容器
问题定位
因为nginx容器内部是通过80端口进行监听的,导致在跳转前端首页时直接携带了此时的80端口,而nginx容器本身是通过81端口进行监听的,从而发生了冲突;
解决方案
尽量docker容器的映射端口保持一致
docker-compose.yml
default.conf
标签:index,conf,端口,nginx,html,一致,Docker,80,端口映射 From: https://www.cnblogs.com/ReturnOfTheKing/p/18295604