I have a server with vhosts conf that looks like this:
NameVirtualHost *:80
# My Virtual Hosts:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName domain
DirectoryIndex index.php index.html
DocumentRoot /var/www/domain/public
# Custom log file locations
LogLevel warn
ErrorLog /var/www/domain/log/error_log
CustomLog /var/www/domain/log/access_log combined
<Directory "/var/www/dailysongfix/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
A typical vhost conf right? Well I also need to develop a few other sites on the server and these sites don't have domains hooked to them yet. How can I view them without a domain pointing at them? I am guessing maybe the IP address and a port, but not sure how to set that up.
If you're going to use named virtual hosts, you need to assign some name to the server. In your example, the host will be addressed by the name
domain
(from theServerName domain
directive). You can try to contact your server by IP address directly by doing something likehttp://123.45.67.89/
but that won't cause Apache to trigger the named virtual host. To do this you will need to add something like this to your/etc/hosts
file on the client:Then, you should be able to use
http://domain/
in your browser. This sets up the mapping between name and IP address locally without having to mess with DNS.The way this works is when the browser sends the HTTP request to the server, it includes whatever text it used after the
//
in the URL in aHost:
header. Apache takes this text in theHost:
header and matches it againstServerName
values in each named virtual host. When it finds a match, it uses that as the server to process the rest of the request. Apache does not need to look up the mapping between the host name and IP address, which is why this works if you only change the client machine configuration.Use "Alias" instead of VirtualHost, it should work out fine if your PHP applications don't require a fixed URL.
Edit: You can add the aliases to the config you pasted above, just add them before the container.
maybe not the best way to go but you always can do as follows:
i know i know - it's not exactly what you asked for but i think can solve your problem.
alternativly if your vhosts have exactly the same configuration just put your webpages in /somewhere/{nameOfDomain} and then share /somewhere as another vhost. then you'll be able to access any paged by going to http://myVhost/{nameOfDomain}. this can cause some security risk if in vhosts you have some access rules [ which would be probably not included in 'another vhost' configuration ].
On any standard packaged apache will be setup for use via ip address. which basically doesnt have a virtual host