1

I'm trying to create a virtual host in apache so I can access a local site via localhost but using a different port than the default :80, what I want is that http://localhost:8080 loads my site directly in the folder I specify, I have the following set up in my httpd-vhosts.conf file which is working partially:

Listen 8080
NameVirtualHost *:8080

<VirtualHost 127.0.0.1:8080>
    DocumentRoot "c:\wamp\www\trend\public"
    ServerName local.trend
</VirtualHost>

If I go to http://localhost:8080 the page loads fine but if I go to http://local.trend then it just shows me the same as if I go to http://localhost is there any way to change it so it works with the server name as well?

Should I edit my hosts file? I currently have:

127.0.0.1 localhost local.trend

Javier Villanueva
  • 3,886
  • 13
  • 48
  • 80

1 Answers1

3

Your hosts file is correct as it stands now.

If you want http://local.trend to go to the same target as http://local.trend:8080 (which is what you have configured above), you'll need to add a separate VirtualHost for that host on port 80:

<VirtualHost 127.0.0.1:80>
    DocumentRoot "c:\wamp\www\trend\public"
    ServerName local.trend
</VirtualHost>
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • I need `http://local.trend` to go to the same target as `http://localhost:8080`, just tried this but didn't help, should I change my `hosts` file? I just have `127.0.0.1 localhost local.trend` right now – Javier Villanueva Jun 30 '12 at 20:31
  • @javiervd Apache won't allow you to serve two different ports from the same VirtualHost config stanza, so you will need to add the stanza for local.trend:80 as above. Make the DocumentRoot the same as used by localhost:80. – Michael Berkowski Jun 30 '12 at 20:51
  • @Michael meant that your web browser on looks on port 80 by default, so you have rewrite your config to look for that as well as 8080. Copying and pasting what he did into your configuration should work just fine. – Mark Jun 30 '12 at 20:51
  • @javiervd Sorry, I confused myself. Don't use the same DocumentRoot as localhost:80, use the same as local.trend:8080 as I had originally. – Michael Berkowski Jun 30 '12 at 20:53