Nginx 到 Sonarqube 的反向代理不起作用。收到 500 错误
使用 docker-compose 文件启动了 3 个 docker 容器,即 nginx、sonarqube 和 docker。 postgres
docker-compose 文件如下:
版本:“3.3”
服务:
sonarqube:
container_name: sonarqube_9
image: sonarqube:9-community
restart: always
ports:
- "9000"
networks:
- sonarnet
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- /data/docker-volumes/sonarqube/conf:/opt/sonarqube/conf
- /data/docker-volumes/sonarqube/data:/opt/sonarqube/data
- /data/docker-volumes/sonarqube/extensions:/opt/sonarqube/extensions
- /data/docker-volumes/sonarqube/bundled-plugins:/opt/sonarqube/lib/bundled-plugins
db:
image: postgres:14
restart: always
ports:
- 5432:5432
networks:
- sonarnet
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- /data/docker-volumes/postgresql:/var/lib/postgresql
- /data/docker-volumes/postgresql/data:/var/lib/postgresql/data
reverse_proxy:
container_name: reverse_proxy
depends_on:
- sonarqube
image: nginx:latest
networks:
- sonarnet
ports:
- 80:80
- 443:443
restart: always
volumes:
- /data/docker-volumes/nginx/conf:/etc/nginx/conf.d/
networks:
sonarnet:
name: sonarnet
driver: bridge
................................................ ...
的 default.config 文件内的 nginx 容器内部
反向代理服务器 {
listen 80;
server_name localhost:9000;
location / {
proxy_pass http://127.0.0.1:9000;
}
}
当在浏览器上尝试访问 http://localhost:80 时 错误 500
我们在屏幕上收到 User_Client日志中的
:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,如 Gecko) Chrome/98.0.4758.102 Safari/537.36" “请求:GET/HTTP/1.1 状态:502 请求_URI:/ 主机:本地主机
Using docker-compose file spinned up 3 docker containers i.e nginx,sonarqube & postgres
docker-compose file below :
version: "3.3"
services:
sonarqube:
container_name: sonarqube_9
image: sonarqube:9-community
restart: always
ports:
- "9000"
networks:
- sonarnet
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- /data/docker-volumes/sonarqube/conf:/opt/sonarqube/conf
- /data/docker-volumes/sonarqube/data:/opt/sonarqube/data
- /data/docker-volumes/sonarqube/extensions:/opt/sonarqube/extensions
- /data/docker-volumes/sonarqube/bundled-plugins:/opt/sonarqube/lib/bundled-plugins
db:
image: postgres:14
restart: always
ports:
- 5432:5432
networks:
- sonarnet
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- /data/docker-volumes/postgresql:/var/lib/postgresql
- /data/docker-volumes/postgresql/data:/var/lib/postgresql/data
reverse_proxy:
container_name: reverse_proxy
depends_on:
- sonarqube
image: nginx:latest
networks:
- sonarnet
ports:
- 80:80
- 443:443
restart: always
volumes:
- /data/docker-volumes/nginx/conf:/etc/nginx/conf.d/
networks:
sonarnet:
name: sonarnet
driver: bridge
.......................................
Inside nginx container inside default.config file for reverse proxy
server
{
listen 80;
server_name localhost:9000;
location / {
proxy_pass http://127.0.0.1:9000;
}
}
When on browser trying to access http://localhost:80
we are getting error 500 on screen
in logs we are getting
User_Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"
"Request: GET / HTTP/1.1
Status: 502
Request_URI: /
Host: localhost
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nginx 容器中的
localhost
指的是 nginx 本身。您需要使用容器名称作为 proxy_pass,例如proxy_pass http://sonarqube_9:9000;
。localhost
within nginx container refers to nginx itself. You need to use container name as proxy_pass, e.g.proxy_pass http://sonarqube_9:9000;
.