-1

I currently have three WordPress sites hosted on Apache with virtual host files to direct the right domain to the right DocumentRoot. Ghost (node.js) just came out and I've wanted to tinker with it and just play around on one of my spare domains. I'm not really interested in moving over to nginx so I'm trying to get Ghost working on Apache via mod_proxy. I've managed to get Ghost working on my spare domain, but I think there's a problem with my virtual host files, as all of my other domains start pointing to Ghost as well. Here are two virtual host files, one for my main WordPress site that works fine, and the second for Ghost. Domains removed and replaced with DOMAIN and DOMAIN2.

DOMAIN

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName DOMAIN.com
ServerAlias www.DOMAIN.com

DocumentRoot /var/www/DOMAIN.com/public_html
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/DOMAIN.com/public_html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

DOMAIN2

<VirtualHost IP:80>
    ServerAdmin EMAIL
    ServerName DOMAIN2.com
    ServerAlias www.DOMAIN2.com

    ProxyPreserveHost on
    ProxyPass / http://IP:2368/
</VirtualHost>

I get the feeling I'm not working with virtual hosts or mod_proxy right, and Google-fu has let me down after many suggested attempts. Any ideas? Thanks!

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89

1 Answers1

0

You tried to mix name-based and IP-based virtual hosting on an IP address. This almost never has the results you expect.

From the documentation:

Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

As a result, any virtual host in a <VirtualHost *:80> block gets completely ignored for any requests coming in on the IP address you defined in your <VirtualHost IP:80> block, and it serves all requests.

You fix this by consistently using either name-based or IP-based virtual hosting for all virtual hosts on a given IP address.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972