so I have site1.com and 192.168.1.100
If I use the IP address Apache doesn't work for site1.com, if I use site1.com the IP address doesn't work. Thoughts?
Can I get both?
I need to access the IP and site1.com and have them point to different directories ( different projects )
Site1.com
#NameVirtualHost site1.com:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/www/site1.com/current/web
ServerName site1.com
ServerAlias site1.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/site1.com/current/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/app_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/app_access.log combined
</VirtualHost>
IP Address
NameVirtualHost 192.168.1.100:80
<VirtualHost 192.168.1.100:80>
#<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/www/ip/current/
ServerName 192.168.1.100
ServerAlias 192.168.1.100
<Directory /home/www/ip/current/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/ip_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ip_access.log combined
</VirtualHost>
UPDATED with Solution
Site1.com
#NameVirtualHost site1.com:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/www/site1.com/current/web
ServerName site1.com
ServerAlias site1.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/site1.com/current/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/app_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/app_access.log combined
</VirtualHost>
IP Address
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/www/ip/current/
ServerName 192.168.1.100
#ServerAlias 192.168.1.100
<Directory /home/www/ip/current/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/ip_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ip_access.log combined
</VirtualHost>
Both your VirtualHost directives need to match the NameVirtualHost directive. So you must either use
*:80
in both VirtualHost and in Name VirtualHost, or you use192.168.1.100:80
in all places.You also do not need to set the same name as
ServerName
andServerAlias
.ServerAlias
is meant for any additional names you want to assign to that virtualhost, in addition toServerName
.Set a virtual host without ServerName as a catch-all virtualhost: