[英]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 反向代理,这样:
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.