How do I reconfigure top level routing on the DigitalOcean Dokku0.2.3/14.04 one-click application?

April 30, 2014 3.9k views
I'm running into an odd issue with the one-click dokku installer where top level routing seems to be broken, or at least odd. I've got DNS records of: mysite.com A *.mysite.com A When I push the first project to dokku@mysite.com:foobar, suddenly ANY subdomain of mysite.com, as well as the root mysite.com, all route to this project. I'd have expected here that all subdomains except foobar don't respond. When I push a second project to dokku@mysite.com:foobarbaz, suddenly ANY subdomain of mysite.com, as well as the root, all route to the SECOND, project, EXCEPT foobar.mysite.com which routes to the first. From this point on, any further projects pushed seem to take over their designated subdomain only, as one would expect. In contrast, I've got a manually installed dokku 0.2.3 on 14.04, and it exhibits the behavior where *anysubdomainofmine* will show an nginx default page, and *subdomains corresponding to projects* will show the proper project. This seems nominally correct to me, with the exception of the nginx "config required" page. My REAL end goal is to have one project served at www.mysite.com AS WELL AS mysite.com (root), with other projects served at their respective subdomains. Has anyone achieved this, with or without the one-click droplet?
4 Answers
I would recommend pushing to an app called "yoursite.com" which will be served on the root domain. Then you could add a virtualhost manually to redirect traffic from www.yoursite.com to yoursite.com:
server {

listen 80;
server_name www.yoursite.com;

return 301 http://yoursite.com$request_uri;
}


Let me know how it goes!
Here's a little more information about who nginx is configured on the one-click app. Each site/app has their own nginx configuration located in "/home/dokku/$YOUR_APP/nginx.conf" It will look like:


upstream $YOUR_APP { server 127.0.0.1:49153; }
server {
listen [::]:80;
listen 80;
server_name $YOUR_APP.$YOUR_DOMAIN.com;
location / {
proxy_pass http://$YOUR_APP;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
}


"/etc/nginx/conf.d/dokku.conf" then includes them all with:


include /home/dokku/*/nginx.conf;


Yes, this solution works fine:

STEP 1

```
include /home/dokku/*/nginx.conf;

#Add this lines
server {
listen 80;
server_name example.com www.example.com *.example.com;

location / {
root html;
index index.html index.htm;
}
}
#To here

ssl_session_cache...
```

STEP 2

Run "/etc/init.d/nginx restart"

After these steps all works fine and apps only takes loaded on the specific sub-domain: [app-name].example.com.

PS: Thank you everybody...
If I may ask, where do you add those DNS records? In your domain site (e.g., godaddy) or in Digital ocean droplet settings?
Have another answer? Share your knowledge.