0

I am trying to have https://mydomain.assuscomm.com/proxmox/ redirect to an internal IP and port on which my proxmox hypervisor is installed.

However i can only get this to work when the location directive is "/". If use the same configuration but change the location URI to "/proxmox/" or any other URI thats not root for that matter, all I get is a blank page. It seems like the location match against the uri succeeds but the redirect some how fails.

For example the config below fails:

server {

  server_name mydomain.asuscomm.com;

  auth_basic           "Administrators Area";
  auth_basic_user_file /etc/nginx/.htpasswd;

  location /proxmox/ {
      proxy_pass https://192.168.1.121:8006/;
      proxy_redirect default;
      proxy_buffering off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain.asuscomm.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.asuscomm.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = mydomain.asuscomm.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



  server_name mydomain.asuscomm.com;
    listen 80;
    return 404; # managed by Certbot

}

If however I change the location match to "/" (see below) then everything works great and I am successfully redirected to the proxmox login page.

What am I doing wrong?

  location / {
      proxy_pass https://192.168.1.121:8006/;
      proxy_redirect default;
      proxy_buffering off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

enter image description here

1 Answer 1

1
  location /proxmox/ {
      rewrite ^/[^\/]+)(/.*) $1 break;
      proxy_pass https://192.168.1.121:8006;
      proxy_redirect default;
      proxy_buffering off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

You need to rewrite the URI, otherwise the target server is trying to open the sub directory, which is probably empty.

2
  • Unfortunately that didnt work. Still seem to be getting a blank page. Based on the logs the REST "GET" calls are failing possibly because the URI being forward for the REST is incorrect. The rewrite should have fixed that but didnt. Is there a way to get additional logging from NGINX that dumps the final rewritten URL or the proxy address before execution. Wondering if there is something wrong with the regular expression itself.
    – iansari
    Mar 29, 2019 at 15:36
  • 1
    You can compile nginx with --with-debug and set logging level to debug.
    – unNamed
    Apr 1, 2019 at 9:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .