0

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>
Phill Pafford
  • 153
  • 1
  • 9

2 Answers2

1

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 use 192.168.1.100:80 in all places.

You also do not need to set the same name as ServerName and ServerAlias. ServerAlias is meant for any additional names you want to assign to that virtualhost, in addition to ServerName.

Jenny D
  • 27,780
  • 21
  • 75
  • 114
  • so by using the IP address instead of *:80 in both configs, this should fix the issue? – Phill Pafford Jun 26 '13 at 13:21
  • If I've understood your question correctly, yes. – Jenny D Jun 26 '13 at 13:23
  • hmm by adding this to both files NameVirtualHost 192.168.1.100:80 I get this warning * Reloading web server config apache2 [Wed Jun 26 09:33:19 2013] [warn] NameVirtualHost 192.168.1.100:80 has no VirtualHosts [Wed Jun 26 09:33:19 2013] [warn] NameVirtualHost *:80 has no VirtualHosts and both sites point to the IP site – Phill Pafford Jun 26 '13 at 13:35
  • FIrwst, it's really hard to read your log when you post it as a comment. Second, please post the relevant part of your new config - i.e. specifically the VirtualHost, ServerName, and NameVirtualHost directives. Post it as an edit to your question, not as a comment. – Jenny D Jun 26 '13 at 14:11
1

Set a virtual host without ServerName as a catch-all virtualhost:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/www/ip/current/
    <Directory>
    ...
blau
  • 738
  • 4
  • 9