当我设置我的反向代理从它自己的端口80转发到它自己的端口8080时,我这样做,我得到以下警告
2016/03/28 22:05:59 [alert] 4193#0: 512 worker_connections are not enough
这可能是无限循环的结果。
在Nginx的configuration:前端反向代理到另一个端口的接受的答案,用户写道:“我假设nginx不是服务器端口5010以及80听,正确吗? 那是因为反向代理人不能转发给自己吗? 还是有另一个原因,为什么这个无限循环正在发生,这个评论只是一个红色的鲱鱼?
以下是我的nginx.conf。 当我转到router.example.com时,会收到警告。 当我删除#### BEGIN BAD LINES #### ,效果很好。
user root; worker_processes 1; worker_cpu_affinity 0101; master_process off; worker_priority 10; error_log /tmp/var/log/nginx/error.log; pid /tmp/var/run/nginx.pid; worker_rlimit_nofile 8192; events { worker_connections 512; } http { log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # Because end of http://nginx.org/en/docs/http/server_names.html server_names_hash_bucket_size 64; # From NixCraft # http://www.cyberciti.biz/tips/using-nginx-as-reverse-proxy.html # Host required server { listen 80 default_server; server_name ""; return 444; } #### BEGIN BAD LINES #### ## Start router proxy ## server { listen 80; server_name router.example.com tomatopaste.example.com; access_log /var/log/nginx/log/router.example.access.log main; error_log /var/log/nginx/log/router.example.error.log; ## send request back to apache1 ## location / { proxy_pass http://192.168.1.1:8080/; proxy_redirect default; proxy_buffering off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ## End ## #### END BAD LINES #### ## Start primary proxy ## server { listen 80; server_name jira.example.com confluence.example.com stash.example.com cacti.example.com; access_log /var/log/nginx/log/lamp.example.access.log main; error_log /var/log/nginx/log/lamp.example.error.log; ## send request back to apache1 ## location / { proxy_pass http://192.168.1.99/; proxy_redirect default; proxy_buffering off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ## End ## map $http_upgrade $connection_upgrade { default upgrade; '' close; } # Websockets server { listen 8686; server_name other.example.com; location / { proxy_pass http://192.168.1.99:8686; proxy_redirect default; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } } }
我认为这个问题不是“为什么逆向代理不能指向自己? 就像“为什么不应该把逆向代理指向自己?”一样。 正如评论者指出的那样, nginx , httpd和其他代理软件可以被configuration为代理连接回自己; 软件或configuration中没有任何东西阻止这一点。
然而,正如你猜测的那样,这个问题成为资源之一。 configuration为将请求代理回自己(通过另一个代理(如httpd )直接或间接代理)的HTTP反向代理需要维护该请求的某个状态(以便将响应发送给调用方)。 如果请求只是简单地循环通过相同的代理(由于configuration),最终会达到一些状态/资源限制, 例如 :
512 worker_connections are not enough
并且请求转发终止。 因此,“为什么不应该反向代理指向自己? 是:“最终反向代理耗尽资源,无法正确服务请求。” 随着链中反向代理的数量增加,导致循环/循环的无意configuration的概率增加,并且随着循环中代理的数量增加,可以更难以检测到这种循环正在发生。 (也许像httpd和nginx这样的应用程序可以检查X-Forwarded-For (假设头部值是可信的)头部来检测这样的循环, 即查看代理本身是否已经出现在该转发链中?
在你的情况下,为了certificate它确实是一个无限循环的转发,我们需要将httpd日志条目与nginx日志条目相关联; 我怀疑这样做的确会看到反向代码图中的循环。
希望这可以帮助!