我正在docker中(使用docker-compose)运行两个http服务器,这些服务器使用express为少数端点提供服务。
尝试从服务器nr1向服务器nr2请求时。
我得到一个错误:
webnode_1 | { Error: connect ECONNREFUSED 127.0.0.1:80
webnode_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1088:14)
webnode_1 | errno: 'ECONNREFUSED',
webnode_1 | code: 'ECONNREFUSED',
webnode_1 | syscall: 'connect',
webnode_1 | address: '127.0.0.1',
webnode_1 | port: 80 }
我正在使用request
库发出GET请求
源服务器NODE版本:节点:11.14.0
目标服务器的节点版本:节点:11.14.0
源服务器:http://test.local
目标服务器:http://api.test.local/api/exchange
目标服务器公开端口:8080
我们还将nginx用于目标服务器配置。
worker_processes 8;
error_log stderr;
user nginx;
worker_rlimit_nofile 100000;
events {
use epoll;
worker_connections 20096;
multi_accept on;
}
http {
set_real_ip_from <ip>/21;
set_real_ip_from <ip>/20;
set_real_ip_from <ip>/22;
set_real_ip_from <ip>/22;
set_real_ip_from <ip>/22;
set_real_ip_from <ip>/18;
set_real_ip_from <ip>/18;
set_real_ip_from <ip>/20;
set_real_ip_from <ip>/20;
set_real_ip_from <ip>/22;
set_real_ip_from <ip>/17;
set_real_ip_from <ip>/15;
set_real_ip_from <ip>/12;
set_real_ip_from <ip>/13;
set_real_ip_from <ip>/22;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
real_ip_header CF-Connecting-IP;
proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=one:1000m max_size=3000m inactive=2m;
proxy_cache_lock on;
proxy_cache_lock_age 3s;
proxy_cache_lock_timeout 3s;
proxy_cache_methods GET POST;
proxy_cache_use_stale timeout;
proxy_temp_path /var/tmp;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 15s;
proxy_cache_valid 500 5s;
include mime.types;
default_type application/octet-stream;
open_file_cache max=20000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
open_file_cache_errors on;
upstream apinode {
server 127.0.0.1:8080;
server 127.0.0.1:8080 max_fails=5 backup;
keepalive 128;
}
access_log off;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
reset_timedout_connection on;
client_max_body_size 2k;
client_body_buffer_size 2k;
large_client_header_buffers 2 1k;
client_header_buffer_size 2k;
client_body_timeout 5s;
client_header_timeout 5s;
send_timeout 3;
server {
listen 0.0.0.0:8080;
server_name api.g4g.local;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_cache one;
proxy_cache_key apik$request_uri$scheme;
proxy_pass http://apinode;
}
}
server {
listen 0.0.0.0:80;
server_name api.test.in;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_cache one;
proxy_cache_key apik$request_uri$scheme;
proxy_pass http://apinode;
}
}
server {
listen 0.0.0.0:80 default_server;
server_name _;
return 403;
}
}
可以从浏览器以及本地脚本访问目标服务器,但不能从源服务器容器内部访问