Host routing problem

My problem is with creating new virtual hosts. Let’s say i created a virtual host for mywebsite.com. I then created another virtual host for mywebsite2.com. I can access mywebsite.com just fine. However, when I go to mywebsite2.com, the address bar goes to my ip address instead. The weird thing is that even though it says it went to the ip address, it actually went to the mywebsite2 folder. In fact, if I enter my server’s ip address, it automatically takes me to mywebsite2.

My questions are: How can I get mywebsite2.com to say that in the address bar (instead of changing to the server IP address)? If fixed, will this allow me to access the apache web server at my ip address (/var/www/)?

If you need clarifications, let me know.

/vital11

See the troubleshooting guide, in particular this section:

http://www.virtualmin.com/documentation/id,troubleshooting_common_problems/#the_wrong_site_shows_up

If VirtualHost/NameVirtualHost misconfiguration is not your problem, come back with something from the logs and the relevant portion of your httpd.conf (the VirtualHost section and the NameVirtualHost directive, and any aliases or redirects that might be coming into play), and we’ll try to help you get it straightened out.

From: apache2.conf (httpd.conf is empty)

[code:1]

Include the virtual host configurations:

Include /etc/apache2/sites-enabled/
ServerName 192.168.1.101
[/code:1]

From: sites-enabled/000-default

[code:1]
NameVirtualHost 192.168.1.101:80
[/code:1]

From: sites-enabled/re-cycledair.com.conf

[code:1]
<VirtualHost 192.168.1.101:80>
SuexecUserGroup "#1001" "#1003"
ServerName re-cycledair.com
ServerAlias www.re-cycledair.com
DocumentRoot /home/re-cycledair/public_html
ErrorLog /home/re-cycledair/logs/error_log
CustomLog /home/re-cycledair/logs/access_log combined
ScriptAlias /cgi-bin/ /home/re-cycledair/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/re-cycledair/public_html>
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
</Directory>
<Directory /home/re-cycledair/cgi-bin>
allow from all
</Directory>
</VirtualHost>
[/code:1]

From: sites-enabled/thedevforum.com.conf

[code:1]
<VirtualHost 192.168.1.101:80>
SuexecUserGroup "#1002" "#1004"
ServerName thedevforum.com
ServerAlias www.thedevforum.com
DocumentRoot /home/thedevforum/public_html
ErrorLog /home/thedevforum/logs/error_log
CustomLog /home/thedevforum/logs/access_log combined
ScriptAlias /cgi-bin/ /home/thedevforum/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/thedevforum/public_html>
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
</Directory>
<Directory /home/thedevforum/cgi-bin>
allow from all
</Directory>
</VirtualHost>
[/code:1]

My problem comes when try to access re-cycledair.com, or my ip address, or the lan ip address.
I checked the config files, and I had an entry that looked like NameVirtualHost * in 000-default, but I removed it and restarted apache. Still the same problem.

ServerName is wrong. This should be a hostname, and is probably the underlying source of the weird redirect you’re seeing. It would (should?) only happen when the request does not match a VirtualHost section, however. But maybe because it comes after those VirtualHost definitions it switches Apache back to single-site hosting mode. I dunno. I reckon I’d move ServerName above the Include directive, and also set it to a sane hostname.

After getting those straightened out, restart Apache, and try it again. Also, be sure your DNS is serving the IP found in the VirtualHost sections for those names. If this is wrong (but still resolves to a name on your box, Apache’s behavior will be to freak out and revert to non-virtual service).