How to remove port number from http://localhost:8123 to use as http://localhost?

23,653

Solution 1

The only way to do this is to change back to 80, or to install a listener on port 80 (like a proxy) that redirects all your traffic to port 8123.

When you enter a server name without a port, port 80 is assumed by default. AFAIK, there is no way to change this behaviour without changing your browser's source code.

The hosts file does not support the kind of redirection you are trying to do. The rules simply fail.

Edit: ah, it might be possible to change the default port in some browsers. Here's an article in MozillaZine for Firefox.

Solution 2

You can remove it with proxyPass and proxyPassReverse

<VirtualHost *>
    ServerName localhost
    ProxyPass / http://127.0.0.1:8123/ 
    ProxyPassReverse / http://127.0.0.1:8123/ 
</VirtualHost>
Share:
23,653
user1421214
Author by

user1421214

Updated on November 01, 2020

Comments

  • user1421214
    user1421214 over 3 years

    I had to change my default apache port number 80 to 8123 (just random number)

    I changed the following files ..

    httpd.conf

    Listen 8123
    ServerName localhost:8123
    

    httpd-vhosts.conf

    NameVirtualHost *:8123
    <VirtualHost *:8123>
      ServerName localhost
      DocumentRoot "C:/xampp/htdocs"
      DirectoryIndex index.php
    </VirtualHost>
    

    Windows Hosts file

    127.0.0.1:8123     localhost
    ::1:8123           localhost
    

    I am using Windows 7.

    After making all these changes, I restarted apache but I am still unable to access http://localhost .... however http://localhost:8123 works fine ... can someone help me find what I am doing wrong here? thanks

  • J.A.I.L.
    J.A.I.L. over 11 years
  • user1421214
    user1421214 over 11 years
    thanks - I'll try changing browser default port
  • J.A.I.L.
    J.A.I.L. over 11 years
    Did you try with different IPs?
  • user1421214
    user1421214 over 11 years
    diff? I tried first with 127.0.0.1 and then tried localhost
  • user1421214
    user1421214 over 11 years
    I give up ... just going to go with port number
  • Pekka
    Pekka over 11 years
    This looks like a good answer but it's crucial that Apache is listening on port 80 for this to work. I'm not sure whether that doesn't defeat the purpose
  • OlivierLarue
    OlivierLarue over 8 years
    Best answer ever! Thanks