Home > Software design >  Nginx reverse proxy without defining server_name?
Nginx reverse proxy without defining server_name?

Time:10-26

I need to access a webserver in a private network, that has no direct access from outside. Opening router ports etc. is not an option.

I try to solve this with a raspi in that network, that i can manage via upswift.io.
Amongst other things, upswift allows temporary remote access to a given port over url's like

http://d-4307-5481-nc7nflrh26s.forwarding.upswift.io:56947/

This will map to a port that i can define. With this, i can access a VNC Server on the pi, start a browser there and access the webserver i need.

But i hope to find a more elegant way, where i can access the Site from my local browser, and where the Pi does not need to run a Desktop.

As far as i found out, this can be done with a reverse proxy like nginx. I found a lot of tutorials on it, but i struggle at one point:

After being able to install nginx and accessing it's default index page from my local browser through the temporary upswift.io url, i can't get it to work as reverse proxy.

I think my conf needs to look like

server {
    listen 80;
    server_name example.com;
    location / {
    proxy_pass http://192.x.x.2;
    }
}

Where example.com would be the name or IP under which the device is accessed. Now, this would not work for me, as that name is dynamic. So i wonder if there's a way to configure nginx so it does not need that name. I would expect that is possible, as the default webserver config works without it too. Are reverse proxies different in that regard?

Or, is there a better way than with a reverse proxy to do what i want?

CodePudding user response:

You could try to define it as a default block

server {
    listen 80 default_server;
    server_name _;
    location / {
      proxy_pass http://192.x.x.2;
    }
}
  • Related