How to map "localhost:8080" to simply "localhost"?
You can set up a reverse proxy to serve at port 80, and forward all requests to 8080.
Apache is one of the web servers that can do this for you. There is a basic reverse proxying example in the mod_proxy documentation.
The hosts file only binds host names to IP addresses.
By default HTTP runs over port 80. So by binding a host name to 127.0.0.1 and then hitting the host name in your browser (over HTTP) you are implying port 80.
You would need to set up a proxy server that listened to port 80 and forwarded the requests on to port 8080. Your web server would still have to run on port 8080
hosts file is to associate a name to an ip.
What you want to do is a firewall duty.
Or you configure the application to run on 80 instead of 8080.
With iptables you could do something like:
iptables -t nat -I PREROUTING -p tcp -i eth0 -d 127.0.0.1 --dport 8080 -j DNAT --to-destination 127.0.0.1:80
You need extra privileges to listen on ports below 1000, which is probably why you are listening on port 8080 rather than port 80. You can set up a reverse proxy using Apache, Squid, Varnish or various other proxies.
Or you could just get the software to listen on port 80 by letting it escalate privileges and passing the correct parameters. What's the software? We'll probably be able to help you get it listening on port 80.
Related videos on Youtube
marcgg 3 months
Using the hosts file, I can't do something like this:
Therefore I will have to write
127.0.0.1 testing http://testing:8080
in order to do the same thing.
The problem is that I need to be able to access the IP without entering any port. Do I have any options to do such a thing?
Admin over 12 yearsI've removed the DNS tags from this, as port bindings have nothing to do with DNS. DNS is simply a mechanism to get an IP from a name and vice versa.
britzm over 12 yearsIt would be better to have this administered by the proxy than routing though though IPtables otherwise this just adds an extra level of complexity to the system. Most people would automatically start looking at the web server configs for a proxy if they had to debug an issue or learn how everything is setup.