0

So, I am trying to load this nginx config that allows for usage of a regex string variable to be passed and proxy'd to the correct corresponding IP address as well as port number that is encrypted using base 64. However when I attempt to encrypt these addresses and pass them back with a return 200, the IP and Port numbers are correct, but NoVnc gives me an error message and just the website skeleton loads but improperly. Any ideas what might be wrong with my config? I believe it is the fact that it is trying to load the regex expression as the address and it is not actually running the perl script first in order to decode it. but there is no real way I can see to test this with out the return 200, and it passes back the correct address... any ideas?

server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
    resolver 8.8.8.8;
    location ~ "^/[a-zA-Z0-9=/]+$" {
  
        try_files $uri $uri/ 
        default_type 'text/plain';       
        # Drop the leading /
        if ($request_uri ~* ^/(.*)$) {
            set $encoded $1;
        }

        # Use Lua to decode the variable
        set $decoded '';
        set_by_lua_block $decoded {
            local cmd = '/etc/nginx/conf.d/decode.pl ' .. ngx.var.encoded
            return io.popen(cmd):read("*a"):gsub("[\r\n]", "")
        }

        #return 200 "decoded: $decoded";
        #Use the $decoded variable in the proxy_pass directive
        proxy_pass http://$decoded;
        rewrite "^/[a-zA-Z0-9=/]+$" /$decoded break;
        # Enable websockets for the noVNC console to work
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_read_timeout 61s;
        proxy_buffering off;
        add_header Cache-Control "no-cache";
    }

}

The above code ^ mixed with error log giving no real errors other than 502 bad gateway.

0 Answers0