如何调试Nginx反向代理问题

Yonatan品牌
2023-01-22 11:07

在我们的JFrog产品前使用反向代理有很多原因。最常见的两种情况是:

  1. 你有几个节点,你想在它们之间建立一个负载均衡器
  2. 您需要将请求重定向到特定端口

在某些情况下,由于反向代理问题,请求将无法到达JFrog产品。
因此,启用是明智的Nginx的日志,因为它可以帮助你确定的根本原因
给定的问题。你可以通过添加的下面几行服务器你的街区
配置文件:access_log /var/log/nginx/$NAME_OF_LOG_FILE-access.log计时;//打开Nginx访问日志

/var/log/nginx/$NAME_OF_LOG_FILE-error.log debug;//这将启用Nginx错误日志与调试模式

下面是一个示例Nginx的日志对于双节点Artifactory集群(Artifactory版本6.x):

##在配置Artifactory HA时添加高可用性条目
上游工艺品{
ip_hash;
服务器hts-il-art-p: 8081;
服务器hts-il-art-s: 8081;

##服务器配置
服务器{
80;
server_name hts-il-db-lb;
proxy_http_version 1.1;
If ($http_x_forwarded_proto = ") {
设置$http_x_forwarded_proto $scheme;

##应用程序特定的日志
Access_log /var/log/nginx/hts-il-db-lb-access.log计时
/var/log/nginx/hts-il-db-lb-error.log调试;
重写^/$ /artifactory/webapp/ redirect;
重写^ / artifactory ? (/ webapp) ?$ /artifactory/webapp/ redirect;
重写^/(v2)/(.*) /artifactory/$1/$2;
chunked_transfer_encoding;
client_max_body_size 0;
位置/工厂/ {
proxy_read_timeout 2400年代;
proxy_pass_header服务器;
proxy_cookie_path ~ * ^ /。* /;
If ($request_uri ~ ^/artifactory/(.*)$) {
proxy_pass https://artifactory/artifactory/ 1美元;


proxy_pass https://artifactory/artifactory/;
http_503非幂等性;
proxy_set_header X-Artifactory-Override-Base-Url
主持人:美元美元http_x_forwarded_proto: / / server_port / artifactory;
proxy_set_header x - forwarded port $server_port;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto
主机$http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Location /artifactory/(api/replication/ replication/ file/streaming) {
proxy_pass https://artifactory: 8081 / artifactory / 1美元;
proxy_buffering;

发布日期:2019年4月22日
最后更新:2021年5月24日

关键词:反向代理,Nginx,调试