请问这个错误是什么问题

问题是这样的,我启动项目后nginx一直报接口404错误。接口如下

但是我在浏览器中使用访问相关服务是没有问题的

我猜测是nginx代理的错误,查看了错误日志提示如下,我搜了一圈没有找到解决方案,求解

2022/04/26 23:43:47 [error] 31#31: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET /api/auth/authenticate/verify/getVerificationCode HTTP/1.1", upstream: "http://127.0.0.1:8500/auth/authenticate/verify/getVerificationCode", host: "localhost", referrer: "http://localhost/manager/login?redirect=/home"

2022/04/26 23:43:47 [error] 31#31: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET /api/auth/authenticate/verify/getVerificationCode HTTP/1.1", upstream: "http://127.0.0.1:8500/auth/authenticate/verify/getVerificationCode", host: "localhost", referrer: "http://localhost/manager/login?redirect=/home"

2022/04/26 23:43:47 [error] 31#31: *3 open() "/etc/nginx/html/50x.html" failed (2: No such file or directory), client: 172.19.0.1, server: localhost, request: "GET /api/auth/authenticate/verify/getVerificationCode HTTP/1.1", upstream: "http://127.0.0.1:8500/auth/authenticate/verify/getVerificationCode", host: "localhost", referrer: "http://localhost/manager/login?redirect=/home"

相关配置如下
nginx配置

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

client_max_body_size 50M;

sendfile on;

keepalive_timeout 65;

server {

listen 80;

server_name localhost;

location /api/ {

proxy_pass http://localhost:8500;

rewrite /api/(.*) /$1 break;

proxy_cookie_path / /api/;

}

location /manager {

alias /usr/share/nginx/html/manager/;

try_files $uri $uri/ /manager/index.html;

index index.html;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

}

docker-compose配置

nginx:

image: nginx:1.20

restart: always

environment:

- TZ=Asia/Shanghai

ports:

- "80:80"

volumes:

- ./nginx/nginx.conf:/etc/nginx/nginx.conf

# - ./nginx/conf.d:/etc/nginx/conf.d

- ./nginx/html:/usr/share/nginx/html

- ./nginx/log:/var/log/nginx

networks:

net:

目录结构

vue配置

  server: {

proxy: {

'/api': {

target: 'http://localhost:8500',

changeOrigin: true,

rewrite: (path) => path.replace(/^\/api/, '')

},

}

},


回答:

感觉是你vue的服务没有能正常启动起来。

或者说你vue服务监听信息不对。

好像你是用的多个容器来部署,这就涉及到容器间通信问题。A容器的localhost并不等于B容器的localhost,反之也然。如果确实是容器中的通信问题,你nginx中的代理地址不能直接用localhost,而需要写能访问的另外容器的IP,或者主机IP(因为另外容器的端口映射出来了)


回答:

你贴的图里nginx用的是80端口,自己用浏览器访问时8500端口。
所以初步看起来是proxy_path有问题,暂时还没空搭建沙盒复现,可以先试试proxy_path填127.0.0.1或者服务器真实的IP/域名。

以上是 请问这个错误是什么问题 的全部内容, 来源链接: utcz.com/p/944402.html

回到顶部