如何调试nginx反向代理?

时间:2016-07-21 07:04:24

标签: http nginx proxy reverse-proxy nginx-location

在我的用例中,我正在尝试使用nginx服务器执行反向代理。我有两个应用程序在两个端口运行。例如,app服务器正在运行端口9090,而api服务器正在8081中运行。

我将在8080的端口中运行nginx服务器。如果我收到/api请求,nginx应该重定向到api服务器。其他请求应该发送到app服务器。

我有以下nginx.conf,

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    upstream app {
      server 127.0.0.1:9090;
      keepalive 64;
    }

    upstream api {
      server 127.0.0.1:8081;
      keepalive 64;
    }
    #
    # The default server
    #
    server {
      listen   8080;
      server_name  howti;

      location /api {
        rewrite /api/(.*) /$1  break;
        proxy_pass http://api;
        proxy_redirect off;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host   $http_host;
        proxy_set_header   X-NginX-Proxy true;
        real_ip_header     X-Forwarded-For;
            real_ip_recursive  on;
        #proxy_set_header   Connection "";
        #proxy_http_version 1.1;
      }

      location /{
        rewrite /(.*) /$1  break;
        proxy_pass http://app;
        proxy_redirect off;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host   $http_host;
        proxy_set_header   X-NginX-Proxy true;
        real_ip_header     X-Forwarded-For;
            real_ip_recursive  on;
        #proxy_set_header   Connection "";
        #proxy_http_version 1.1;
      }

        # redirect not found pages to the static page /404.html
        error_page  404  /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
}

但它不起作用。我无法在nginx中调试请求?有人可以帮我吗?感谢

0 个答案:

没有答案