Answer a question

I have a strange problem with using a nginx as a reverse proxy for my Zeppelin instance. I will try to describe the problem below.

I am using an EC2 instance as the reverse proxy to access the Zeppelin instance. Just a note in front of that is an AWS ALB sitting as "forward proxy", this way I can use a friendly URL's for exposing the UI's. The path based routing on the AWS ALB is configured correctly.

  1. The request is coming to AWS ALB with domain subdomain.domain.com/ds where I am using a path based routing to match all requests that are hitting the /ds as a path to my target group.

  2. The incoming request is then passed to Nginx instance, which is working well. The problem is that if I am using a URL without trailing slash, the Nginx simply timeouts.

The configuration is below:

# Zeppelin
server {
    listen 541;
    location /ds {
        rewrite ^/ds/(.*)$ /$1 break;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://10.10.10.10:8890/;
        proxy_redirect http://10.10.10.10:8890/ $scheme://$host/ds;
    }
    location /ds/ws {
        proxy_pass http://10.10.10.10:8890/ws;
        proxy_http_version 1.1;
        proxy_set_header Upgrade websocket;
        proxy_set_header Connection upgrade;
        proxy_read_timeout 86400;
    }
}

Also, bellow is the most simple example that I am using for RStudio.

server {
    listen 542;


    location /ds {
      rewrite ^/ds/(.*)$ /$1 break;
      proxy_pass http://10.10.10.10:8787;
      proxy_redirect http://10.10.10.10:8787/ $scheme://$host/ds/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_read_timeout 20d;
    }
}

In case that trailing slash is not provided, I am getting

/ds not found

Answers

In your location block:

location /ds {
    rewrite ^/ds/(.*)$ /$1 break;
    ...  
    proxy_pass ...
}

URIs which begin with /ds/ will match the regular expression and be rewritten without the initial /ds. However, the URI /ds does not match the regular expression and will be passed to the upstream application as /ds.

There are a number of ways to fix the problem, but the simplest solution is to make the second / in the regular expression optional by adding a ? operator.

For example:

rewrite ^/ds/?(.*)$ /$1 break;
Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐