Running WordPress and Ghost on Apache with mod_proxy

Jack Perry asked:

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.


<VirtualHost *:80>
ServerAdmin [email protected]

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

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

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 ::1/128


<VirtualHost IP:80>
    ServerAdmin EMAIL

    ProxyPreserveHost on
    ProxyPass / http://IP:2368/

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!

My answer:

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.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.