我正在使用 docker compose 并尝试使用 NGINX 作为反向代理和带有 postgres 的节点服务器。 当我使用主机时,我已成功从 nodejs 获取数据。但是在同一个局域网中使用不同的计算机时,我没有收到任何数据/响应。从控制台我可以看到它正在使用 127.0.0.1:3001/... 获取数据但失败了。
我的 nginx 配置是这样的:
upstream backend {
server nodejs:3001;
}
server {
root /var/www/html;
index index.html;
server_name www.ttttest.com;
location / {
root /var/www/html;
}
location /api {
proxy_pass http://backend;
}
}
我明白了,可以使用主机 IP:3001/.. 获取数据,但我想使用 localhost:3001 地址从节点服务器获取数据。 这怎么可能。任何帮助将不胜感激。 我的中间件 conf 看起来像这样:
angular.module('ui.bootstrap.demo').controller('testController', function($scope,DTOptionsBuilder,$http, DTColumnBuilder) {
$scope.customers = [];
function getAll() {
var url = "/api/customers/all/sql";
// do getting
$http.get(url).then(response => {
$scope.getDivAvailable = true;
$scope.customers = response.data;
console.log($scope.customers);
}, response => {
$scope.postResultMessage = "Error Status: " + response.statusText;
});
}