Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to set up apache virtual hosts on Ubuntu 12.04 lts. I followed this guide here http://www.debian-administration.org/articles/412 except I used /var/www not /home/www. Ive set the document root folder to 755 permissions. It is a server I am running out of my house, so its possible it could be a problem with my router I would think? I am not using a proxy.Is there a certain way port forwarding needs to be set up to run vhosts? (And yes, It worked fine before vhosts. I get a 502 response error (bad gateway). Here are my two enabled sites

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName www.functioncreate.com
    ServerAlias functioncreate.com

    # Indexes + Directory Root.
    DirectoryIndex index.html
    DocumentRoot /var/www/functioncreate/htdocs/

    # CGI Directory
    ScriptAlias /cgi-bin/ /var/www/functioncreate/cgi-bin/
    <Location /cgi-bin>
            Options +ExecCGI
    </Location>

    # Logfiles
    ErrorLog  /var/www/fucntioncreate/logs/error.log
    CustomLog /var/www/functioncreate/logs/access.log combined
</VirtualHost>

And the second one:

#
#  Example.com (/etc/apache2/sites-available/www.example.com)
#
<VirtualHost *:80>
    ServerName www.labelleviemodesto.com
    ServerAlias labelleviemodesto.com

    # Indexes + Directory Root.
    DirectoryIndex index.html
    DocumentRoot /var/www/labellevie/htdocs/

    # CGI Directory
    ScriptAlias /cgi-bin/ /var/www/labellevie/cgi-bin/
    <Location /cgi-bin>
            Options +ExecCGI
    </Location>


    # Logfiles
    ErrorLog  /var/www/labellevie/logs/error.log
    CustomLog /var/www/labellevie/logs/access.log combined
</VirtualHost>

My httpd.conf has nothing in it. I have tried with "default" site enabled and disabled. The only things in apache that I have touched is the new sites I created in sites-available and then symlinked to sites-enabled via a2ensite (followed by an apache reload) and then creating virtual.conf in conf.d with this inside:

#
#  We're running multiple virtual hosts.
#
  NameVirtualHost *

Here is my error.log

Warning: DocumentRoot [/var/www/functioncreate] does not exist
Warning: DocumentRoot [/var/www/labellevie] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Wed Feb 12 23:40:40 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
[Wed Feb 12 23:40:40 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations
[Wed Feb 12 23:44:55 2014] [notice] Graceful restart requested, doing restart
Warning: DocumentRoot [/var/www/functioncreate] does not exist
Warning: DocumentRoot [/var/www/labellevie] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Wed Feb 12 23:44:55 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
[Wed Feb 12 23:44:55 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations
[Wed Feb 12 23:46:06 2014] [notice] Graceful restart requested, doing restart
Warning: DocumentRoot [/var/www/labellevie] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Wed Feb 12 23:46:06 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
[Wed Feb 12 23:46:06 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations
[Wed Feb 12 23:46:29 2014] [error] [client 10.0.0.14] File does not exist: /var/www/functionCreate/favicon.ico
[Thu Feb 13 00:22:45 2014] [notice] Graceful restart requested, doing restart
Warning: DocumentRoot [/var/www/labellevie] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Thu Feb 13 00:22:45 2014] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Thu Feb 13 00:22:45 2014] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Thu Feb 13 00:22:45 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
[Thu Feb 13 00:22:45 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
(2)No such file or directory: apache2: could not open error log file /var/www/fucntionCreate/logs/error.log.
Unable to open logs
[Thu Feb 13 12:03:37 2014] [warn] pid file /var/run/apache2.pid overwritten -- Unclean shutdown of previous Apache run?
[Thu Feb 13 12:03:37 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations
[Thu Feb 13 12:03:57 2014] [notice] caught SIGTERM, shutting down
[Thu Feb 13 12:03:58 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations
[Thu Feb 13 12:04:23 2014] [error] [client 166.137.191.15] File does not exist: /var/www/favicon.ico
[Thu Feb 13 12:04:57 2014] [error] [client 166.137.191.15] File does not exist: /var/www/favicon.ico
[Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php
[Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php5
[Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php-cgi

[Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php5
[Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php-cgi
[Thu Feb 13 12:05:41 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php.cgi
[Thu Feb 13 12:05:41 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php4
[Thu Feb 13 12:09:18 2014] [notice] Graceful restart requested, doing restart
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Thu Feb 13 12:09:19 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
(2)No such file or directory: apache2: could not open error log file /var/www/fucntionCreate/logs/error.log.
Unable to open logs
share|improve this question
    
is your server behind a proxy? are you behind a proxy? You should provide some logs but even if you config were wrong, you wouldn't be getting a 502 error. A 502 error usually happens if you have a backend server that is not responding. –  jijix Feb 14 '14 at 15:30
    
I am not behind a proxy. I added the error.log. It is a server I am running out of my house though, so maybe its a router problem? See my updated question –  cojomojo Feb 15 '14 at 19:40
    
Have you yet fixed the obvious problem? –  Michael Hampton Feb 15 '14 at 19:45
    
As in the documentroot not being found? I am looking into that now, its there... i checked spelling everything. Also I am not getting those errors anymore, no errors have shown up in 2 days of trying to access it, reloading apache, tinkering ect –  cojomojo Feb 15 '14 at 19:46

1 Answer 1

up vote 0 down vote accepted

I have a few tips:

Check to see if there is a difference in behaviour on both sides of the router. Let's say your server's internal IP is 192.168.0.10. Edit the hosts file on your test machine (/etc/hosts on Mac and c:\windows\system32\driver\etc\hosts on Windows - remeber to use sudo on Mac or "run as admin" on Windows, otherwise you won't be able to edit the file) and add the following lines to it (substitute 192.168.0.10 with your actual internal/home network server IP):

192.168.0.10    www.labelleviemodesto.com labelleviemodesto.com
192.168.0.10    www.functioncreate.com functioncreate.com

Ping all of these domain names to make sure that you're hitting the right IP. nslookup won't work, since it will only query DNS, which will give you the proper (external) IP for the server and ignore the hosts file override. Ping, and all other programs, will honour the hosts file override. Obviously you need to do this on the inside of your private (home) network, say on wi-fi. If the ping targets the internal IP (192.168.0.10) for all 4 domains (this is important, since, for example, functioncreate.com may redirect to www.functioncreate.com and vice versa, so you want to make sure that no matter what, you are talking to the internal IP directly, without the router in the middle).

Anyway, bottom line: see if you still get the 502 error. If you do, then it's most likely coming from Apache and there's something wrong with your config files. If it works OK via the private IPs, but when you go from the outside and access this server through the router you get the 502 error, then the issue lies with your router configuration.

My guess: it's the router. You don't seem to have anything resembling reverse proxying in your Apache config.

Final note: Make sure you have only one and only one NameVirtualHost line in all your .conf files. If you have more than one, or, if your VirtualHost parameters don't correspond exactly to your NameVirtualHost parameter, you will get weird, unexpected results. For example, since you already have all your virtual hosts defined like so:

VirtualHost *:80

Make sure that the one and only NameVirtualHost line in all of your Apache config files looks like this:

NameVirtualHost *:80

You should not be seeing lines like these in your logs!

[Wed Feb 12 23:46:06 2014] [warn] NameVirtualHost *:80 has no VirtualHosts

Granted, this is not a straight answer, but I hope it will bring you closer to the answer. :)

share|improve this answer
    
I did two things to resolve the issue, first I upgraded apache2 and reconfigged everything... still no dice. SOOO I did what you said an pinged them from my computer, and that led me to finding a small error in my hosts file on the server. Now it works perfect, thank you! –  cojomojo Feb 17 '14 at 3:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.