Question

I'm building a website on my laptop that needs to be referenced via a custom hostname, instead of deep off of the localhost directory.

I need this site to be referenced locally via http://project.name/

I have this working by having created a new entry in my hosts file as well as a virtual host entry in my apache vhosts conf.

I also want to allow external users to view my site. They would need to access it by my ip address plus a port number, I imagine.

How do I do this?

I assume 'Listen 8080' needs to be added to apache.conf.

Do I create a new vhosts entry that duplicates the one I created before for the local host name, but with a "localhost:8080" name? (this smells bad).

Or can the existing vhosts entry be amended to also listen on localhost:8080?

To further clarify, I need:

 http://project.name and
 http://localhost:8080 

to reference the same, exact site. This is because I need to create the site with a custom host name. My image references, for example need to start with "/images/example.jpg" instead of relative references. This is because the tech dept would have to do 10 mins of extra work. :^)

Thanks, Scott

Was it helpful?

Solution

Rather than specifying a host (such as localhost) in your vhost directives, use * instead. This will allow you to reach that virtual host via different host names. If you omit ServerName from the block completely, that will allow you to hit the same site via http://localhost:8080, or from outside the machine via http://<ip address>:8080.

NameVirtualHost *:8080

<VirtualHost *:8080>
   # your stuff
</VirtualHost>

You can then tune what interface these vhosts use with the Listen directive itself:

Listen 8080              # you can hit the sites from outside your machine, OR
Listen 127.0.0.1:8080    # no access outside your machine

Use apachectl -S to double check your vhost settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top