0

I am having multiple apps each listening on different ports and i am trying to configure nginx so i can proxy pass to each of them separately.

I am able to configure the root location of my domain to proxy pass to a bokeh app which is listening on port 5006 using this config:

server {
    listen 80 default_server;
    listen 443 ssl;

    root /var/www/mydomain/html;
    index index.html index.htm index.nginx-debian.html;


    server_name mydomain www.mydomain;
    ssl_certificate     /etc/letsencrypt/live/mydomain/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/mydomain/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:5006;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host:$server_port;
        proxy_buffering off;
    }

The above part works. However, when i try to create an additional location so that i can have the location / serving a landing page (from root) and then location /env to proxy to localhost:5006 it shows empty page at mydomain/env. Here is the config i am trying with:

server {
    listen 80 default_server;
    listen 443 ssl;

root /var/www/mydomain/html;
index index.html index.htm index.nginx-debian.html;


server_name mydomain www.mydomain;
ssl_certificate     /etc/letsencrypt/live/mydomain/fullchain.pem;
ssl_certificate_key  /etc/letsencrypt/live/mydomain/privkey.pem;

location / {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host:$server_port;
    proxy_buffering off;
}

location /env/ {
    rewrite ^/env/(.*)$ /$1 break;
    proxy_cache_bypass $http_upgrade
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    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 $host:$server_port;
    proxy_buffering off;
    proxy_pass http://127.0.0.1:5006;
}

}

It would be great if someone could point out on where i am making the mistake.

Thanks.

mgn
  • 129
  • 1
  • 10
  • I would try to remove the rewrite, and instead add a trailing slash to your proxy_pass: `proxy_pass http://127.0.0.1:5006/;` https://stackoverflow.com/a/22759570/1497533 – ippi Oct 15 '20 at 04:40
  • I tried these changes, still didn't work, unfortunately. – mgn Oct 15 '20 at 08:25
  • When I tried with location /envp/ and commenting out rewrite, I get this error msg at nginx error log: "/var/www/mydomain.net/html/env/index.html" is not found (: No such file or directory), server: tdmworld.net, request: "GET /env/ HTTP/1.1", host: "mydomain.net" (By the way i am serving a bokeh app at 5006 and env is the name of the file) – mgn Oct 15 '20 at 08:33

0 Answers0