简体   繁体   English

Nginx 反向代理上的连接被拒绝

[英]Connection refused on Nginx Reverse Proxy

I have a server machine where I have configured a reverse proxy using Nginx.我有一台服务器机器,我使用 Nginx 配置了反向代理。 It is configured to cache the files it get from a CDN and server them.它被配置为缓存它从 CDN 获取的文件并为它们提供服务器。 There is a firewall and a forward-proxy server configured in the network which the server belongs to.服务器所属的网络中配置有防火墙和转发代理服务器。 When I tried to connect to the server machine, it was returning 502. When I checked the nginx error logs, it was saying it could not connect to the upstream (which is the CDN).当我尝试连接到服务器机器时,它返回 502。当我检查 nginx 错误日志时,它说它无法连接到上游(即 CDN)。 I want nginx to forward the request it gets, to the CDN through the forward-proxy(which is already configured in the network).我希望 nginx 通过转发代理(已在网络中配置)将它收到的请求转发到 CDN。 What change do I need to make?我需要做出什么改变?

Here is my nginx.conf这是我的nginx.conf

worker_processes 1;
daemon on;
error_log /var/log/error.log;
pid /var/run/nginx.pid;
events
{
 worker_connections 1024;
}
http
{
 proxy_cache_path /path/to/the/cache/folder/1 levels=1:2 keys_zone=cache_common:512m max_size=128g inactive=7d use_temp_path=off;
 proxy_cache_path /path/to/the/cache/folder/2 levels=1 keys_zone=cache_version:1m max_size=128M inactive=60s use_temp_path=off;
 server
 {
 listen 8000 default;
 access_log /var/log/access.log;

 location /url1/ {
 proxy_cache cache_version;

 proxy_pass http://this-is-my-cdn-url.com; 
 }

 location /
 {
 proxy_cache cache_common;
 proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
 proxy_cache_valid 404 1d;
 proxy_pass http://this-is-my-cdn-url.com;
 }
 }
}

I had got the solution to my issue.我已经解决了我的问题。 What I wanted to setup was an nginx reverse proxy, so that:我想要设置的是 nginx 反向代理,这样:

  • it will receive requests from the client它将接收来自客户端的请求
  • replace the host part in that URL with another CDN I wanted to access用我想访问的另一个 CDN 替换 URL 中的主机部分
  • forward this request to the CDN, through a forward proxy.通过转发代理将此请求转发到 CDN。

I had to access the CDN through the nginx server, because I wanted to cache the contents served, and thus reduce the number of hits to CDN.我不得不通过 nginx 服务器访问 CDN,因为我想缓存服务的内容,从而减少对 CDN 的点击次数。

Well, the solution I got is this:好吧,我得到的解决方案是这样的:

myconfig.conf

server {
listen 8000;
server_name my-domain-name.com;

location / {

rewrite ^(.*)$ "://the-cdn-domain-name.com$1";
rewrite ^(.*)$ "https$1" break;
proxy_pass http://X.X.X.X:1234; # this is my forward proxy IP
}
}

This is what you have to include in the conf.d directory.这是您必须包含在 conf.d 目录中的内容。 I have skipped the contents we have to give by default in nginx.conf我已经跳过了我们必须在nginx.conf中默认提供的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ERR_CONNECTION_REFUSED NGINX 代理反向 - ERR_CONNECTION_REFUSED NGINX PROXY REVERSE 使用nginx作为反向代理时,连接到上游时连接被拒绝 - Connection refused while connecting to upstream when using nginx as reverse proxy 连接被拒绝:Docker容器中的Nginx HTTPS反向代理 - Connection refused : Nginx HTTPS reverse proxy in docker container Docker nginx 反向代理错误 - 502 网关错误 - 连接被拒绝 - Docker nginx reverse proxy error - 502 bad gateway - connection refused 当尝试连接到节点应用程序作为反向代理时,Nginx连接被拒绝 - Nginx connection refused, when trying to connect to node app as reverse proxy Nginx 反向代理到后端给出错误 ERR_CONNECTION_REFUSED - Nginx reverse proxy to backend gives an error ERR_CONNECTION_REFUSED Nginx 代理到 CFSS 连接被拒绝 - Nginx proxy to CFSS Connection refused 为什么NGINX反向代理$ .ajax帖子给出“net :: ERR_CONNECTION_REFUSED” - Why does NGINX reverse proxy $.ajax post give “net::ERR_CONNECTION_REFUSED” nginx反向代理上游在docker-compose中失败并显示连接被拒绝的消息 - nginx reverse proxy upstream fails in docker-compose with connection refused message Docker Nginx反向代理返回502错误的网关“连接到上游时连接被拒绝” - Docker nginx reverse proxy returns 502 bad gateway “connection refused while connecting to upstream”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM