How to map "localhost:8080" to simply "localhost"?


Solution 1

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.

Solution 2

The hosts file only binds host names to IP addresses.

By default HTTP runs over port 80. So by binding a host name to 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

Solution 3

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 --dport 8080 -j DNAT --to-destination

Solution 4

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

Author by


Trying to build useful software. Find me on twitter or give my blog a read!

Updated on September 17, 2022


  • marcgg
    marcgg about 1 year

    Using the hosts file, I can't do something like this: testing

    Therefore I will have to write testing

    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
      Admin over 13 years
      I'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
    britzm over 13 years
    It 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.