Reputation: 108
Remote Server: Ubuntu 14.04 Headless
I've setup Couchdb v2.0.0 successfully, and can access it remotely via www.[mydomain].com:5984/_utils
I want to create a subdomain to access this URL, something like dbadmin.[mydomain].com
First, I created a subdomain of db.[mydomain].com (Here's the apache2 vhost config:)
<VirtualHost *:80>
ServerName db.[mydomain].com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://db.[mydomain].com:5984/
ProxyPassReverse / http://db.[mydomain].com:5984/
</VirtualHost>
Note: I have replaced [mydomain] with the actual domain ;P
I then created an A Record with my DNS Registrar as follows:
db A [PublicIP]
and then a SRV Record:
_db._tcp.db SRV 0 5 5984 db.[mydomain].com
and I test it by going to http://db.[mydomain].com/ on my laptop
Result: {"couchdb":"Welcome","version":"2.0.0","vendor":{"name":"The Apache Software Foundation"}}
So a success, I think. Now, I create the dbadmin subdomain. Apache2 vhost config:
<VirtualHost *:80>
ServerName dbadmin.[mydomain].com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://db.[mydomain].com:5984/_utils
ProxyPassReverse / http://db.[mydomain].com:5984/_utils
</VirtualHost>
Then another A Record:
dbadmin A [PublicIP]
Followed by another SRV Record:
_dbadmin._tcp.dbadmin SRV 0 5 5984 dbadmin.[mydomain].com
I test it by visiting http://dbadmin.[mydomain].com
Result: {"error":"unauthorized","reason":"You are not a server admin."}
I have spent far too many hours trying to suss out the proper way of doing this. I've tried all sorts of configurations, settings, DNS Records, changing couch's local.ini, proxy settings... You get the idea.
Please, elucidate how I can simply redirect a subdomain to either the server's public IP + port + path or the server's root domain + port + path?
Upvotes: 1
Views: 788
Reputation: 108
I solved this with mod_rewrite in the VHost config:
<VirtualHost *:80>
ServerName dbadmin.[mydomain].com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://db.[mydomain].com:5984/
ProxyPassReverse / http://db.[mydomain].com:5984/
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/_utils
RewriteRule ^/$ /_utils/$1 [R,L]
It appears that I didn't even need the SRV Record, either. Groovy!
Can anyone succinctly explain to me what the Regex for this condition and rule are actually doing? I know at a basic level that it looks for /_utils in the query, and if not there, it puts it there...
The rule does however remove the protocol identifier 'http://' from the beginning of the URL, which is rather annoying... Can anyone explain why, and how to prevent that from happening?
Upvotes: 1