My apologies if this is not sufficient for an answer, I don't have enough rep to comment here.
I think /etc/hosts is possibly the best option. I don't know what your teardown process is, but you could add removing the
/etc/hosts entry as part of it.
Also I think the port change won't work with a
/etc/hosts solution. Can you map
Then you could add something like
127.0.1.1 internal-wiki.example to
/etc/hosts and remove the line when you stop the tunnel like so:
sed -i '' '/127.0.1.1 internal-wiki.example/d' (be sure to test that before running live of course).
This should allow you to use
http(s)://internal-wiki.example:8000 in your browser.
It's not a perfect solution, but anything better (such as port mapping) I think would require an http proxy running locally.
For what it's worth, adding and removing host entries is how Parallels makes VMs addressable by hostname. This is added to my
/etc/hosts while my
xu17 VM is running:
172.20.10.112 xu17.shared xu17 #prl_hostonly shared
Of course running an nginx proxy would handle this nicely, but it might be a bit more setup than you're looking for?
A simpler option with netcat might work depending on the web application.
# make fifo for second nc to transfer response back to first nc
nc -lk 8001 < /tmp/proxy.pipe | nc internal-wiki.example 8000 > /tmp/proxy.pipe
Then when you close the tunnel, you can kill the
nc process and delete