2

I'm running local Apache on my mac for development, and also have node.js server running at http://127.0.0.1:8000/.

I use .dev domain for Apache projects and would like .node domain to redirect to node.js server. I have virtual hosts set up as follows:

<VirtualHost *.dev:80>
    VirtualDocumentRoot "/www/sites/%1/wwwroot"
    ServerName sites.dev
    ServerAlias *.dev
    UseCanonicalName Off
</VirtualHost>

<VirtualHost *.node:80>
    ServerName sites.node
    ProxyPass "/" "http://localhost:8000"
    ProxyPassReverse "/" "http://localhost:8000"
</VirtualHost>

However, when I try to apply these settings, I get the error:

[core:error] [pid 8594] (EAI 8)nodename nor servname provided, or not known: 
AH00547: Could not resolve host name *.node -- ignoring!

I should note that .dev domain works as expected, and node.js server is reachable at http://localhost:8000/, just not at, say, http://test.node/.

Am I missing something here?

1

Don’t you just hate when people make rookie mistakes and run to stackexchange for an answer?

Here’s what is being done wrong here:

  1. Making sure that the custom domain actually resolves to localhost is always a kosher thing to do.

For homebrew dnsmasq on mac, this will do the trick:

echo 'address=/.no/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf

And then OS X should be told to look up custom domain locally:

sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/no'

Custom domains 101 really.

  1. VirtualHost rule for proxy redirect should appear as soon as possible in the configuration file. Otherwise, Apache might redirect your custom domain request to localhost without appending the custom port :8000.

Like this:

<VirtualHost *.no:80>
    ServerName sites.no
    ProxyPreserveHost On
    ProxyPass "/" "http://localhost:8000/"
    ProxyPassReverse "/" "http://localhost:8000/"
</VirtualHost>

<VirtualHost *.dev:80>
    VirtualDocumentRoot "/www/sites/%1/wwwroot"
    ServerName sites.dev
    ServerAlias *.dev
    UseCanonicalName Off
</VirtualHost>
  1. Custom domain .node is not currently a valid top-level domain, according to IANA. Changing it to something valid, like .no, prevents that pesky Safari from initiating Google search on requests such as test.no. (Say goodbye to the real .no sites out there.)

And Robert’s your father’s brother.

0
<VirtualHost *.dev:80>
    VirtualDocumentRoot "/www/sites/%1/wwwroot"
    ServerName sites.dev
    ServerAlias *.dev
    UseCanonicalName Off
</VirtualHost>

<VirtualHost *.node:80>
    ServerName sites.node
    ProxyRequests on
    RewriteEngine on
    <Proxy *>
             Order deny,allow
             Allow from all
    </Proxy>
    ProxyPass "/" "http://localhost:8000"
    ProxyPassReverse "/" "http://localhost:8000"
</VirtualHost>

How does this work?

1
  • Sadly, the same thing happens. For testing purposes I commented out the working <VirtualHost *.dev:80>. It seems, the error pops up with any domain I put in the form of *.xxx:80. It's almost as if *.dev:80 is the only option that works. – CBlew Aug 17 '17 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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