Dokku - Add domain after setup - node.js

I installed Dokku on my Digital Ocean droplet, but did it before setting my dns records, so Dokku was installed on IP. Now I changed my dns record, so site can be accessed through site.com. I can access my previously created Dokku containers through site.com:port, how can I change Dokku settings to access my app like this - appname.site.com

Per https://github.com/progrium/dokku:
Set up a domain and a wildcard domain pointing to that host. Make sure
/home/dokku/VHOST is set to this domain. By default it's set to
whatever hostname the host has. This file is only created if the
hostname can be resolved by dig (dig +short $(hostname -f)). Otherwise
you have to create the file manually and set it to your preferred
domain. If this file still is not present when you push your app,
dokku will publish the app with a port number (i.e.
http://example.com:49154 - note the missing subdomain).
To fix the issue, you will first need to update the /home/dokku/VHOST file, adding the domain name -- this will fix any newly generated deployments, but existing apps will need to be deleted from the /home/dokku directory by name (/home/dokku/foo, /home/dokku/bar, etc.) and redeployed for this change to take effect, since each Dokku application has a separate nginx.conf within those /home/dokku/ paths and those will need to be re-written.

It is indeed not necessary to destroy and recreate apps. First, dokku domains:report tells you if global VHOSTS are already enabled or not. If not, run
dokku domains:add-global yourdomain.tld
echo yourdomain.tld | sudo tee -a /home/dokku/VHOST
dokku domains:add myapp myapp.yourdomain.tld
dokku domains:enable myapp
The first of these adds yourdomain.tld to /home/dokku/HOSTNAME. It should also add it to /home/dokku/VHOST, but it doesn't. So that needs to be done manually. Then tell dokku what (sub)domain you want to access myapp on. The last command sets the NO_VHOST variable for myapp to false.

To extend #shirkey answer: you don't need to re-create (destroy and create again) an app in order to apply those changes. You can manually create VHOST file inside /home/dokku/$APP/ directory (as dokku user) then remove NO_VHOST setting (dokku config:unset $app NO_VHOST) and change DOKKU_NGINX_PORT to 80 (dokku config:set $app DOKKU_NGINX_PORT=80) and restart the app (dokku ps:restart $app).

$ echo "example.com" > /home/dokku/VHOST

If you still could add a subdomain. These are the points to check.
Example: add myapp.example.com.
1, DNS(e.g. Namecheap)
If you are using Cloudflare, Check if Custom DNS is set to Cloudflare.
2, CDN(e.g. Cloudflare)
Check if it has A record like this.
Type | Name | Content
A | myapp | public ip address of Digital ocean server
3, VPS(e.g. Digital Ocean)
If you use Cloudflare you don’t have to set up Domain setting on Digital Ocean.
4, Dokku
Is port mapping set up properly? dokku proxy:report to check port 80
is mapped to the port of container.
Is the server running? Use curl from inside the server.
If you still could not locate the cause of the problem, check nginx config file like /home/dokku/appname/nginx.conf /etc/nginx/nginx.conf manually.
Example /home/dokku/appname/nginx.conf file
server {
listen [::]:80;
listen 80;
server_name myapp.example.com;
location / {
proxy_pass http://myapp-3030;
}
upstream myapp-3030 {
server 172.17.0.4:3030;
}

Related

How do I set up my Linux Azure VM so that I can connect via a browser?

I'm working on a Linux VM on Azure which was set up by someone else (so I don't know all the details). I'm trying to connect it to a domain name.
The server has a "Hello World" program, so when I go to "example.com" I should be seeing "Hello World". Currently I'm just getting
Safari can't open the page "http://example.com" because Safari can't find the server "my domain.com"
I thought I'd start with making sure that the IP address connects to the server (which it did at one point. So I enter the IP address of the server (let's say it's "12.345.678.901") in the browser, and it can't connect... I get the error
Can't open the page "12.345.678.901" because the server where this page is located isn't responding
There's an Inbound port rule to allow connections for port 8080, so I tried "12.345.678.901:8080" but this time got
Can't open the page "12.345.678.901:8080" because Safari can't connect to the server
I don't know what to try next. Presumably something needs to be enabled on the server to allow the browser to connect?
The other inbound port rules are ssh on port 22 (TCP) and then what I assume are the standard Azure ones (I can't edit or delete them anyway).
To view your Linux VM inside the browser, you need to install a web server. Easiest to install and get working straight away is nginx.
First thing you need to do is SSH(port 22) into your VM using the username and IP address of the machine:
ssh username#ipaddress
Which will prompt you to enter a passphrase to gain access to the VM.
This also assumes your SSH public key exists inside ~/.ssh/authorized_keys on the VM. If you don't have this setup then you need to get the owner of the VM to copy your public key into this file. Otherwise you won't be able to connect and get a Permission denied (publickey) error.
Assuming the above works, you can install the nginx webserver with the following two commands:
sudo apt-get -y update
sudo apt-get -y install nginx
Then once this web server is installed, add an HTTP inbound port 80 rule inside the network settings. For security reasons, having your web server listen on this port is probably unsecure long term. Its just easier to get working when you choose this port to begin with, because its the default.
You can see what the default listening port by viewing the server configuration host file with cat /etc/nginx/sites-available/default:
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
Which shows the default port of 80. You can change this default port to 8080, then run sudo service nginx restart to restart the server and apply the changes. Additionally, you can have a look at this How to make Nginx Server Listen on Multiple Ports tutorial, which goes into more depth on how to configure listening ports for nginx webservers.
You should then be able to view your VM from a browser window(blurred out my IP address for security reasons):
You can also have a look at this Quickstart: Create a Linux virtual machine in the Azure portal tutorial for a step by step on how to get this setup in Azure.
You should first check to see if you have an entry for http://example.com. The reason could be that you do not have a DNS Entry and when you are trying to connect to it via the browser. Since you tried connecting to it via IP and it still did not work, I would suggest you check your Webserver configurations to make sure it is correctly listening for port 8080. Also, ensure that your webserver is also turned on as well. You can tail the webserver log and try to hit it via the IP like you did earlier and see if you see any errors in the logs. It would at least tell you if your request you are making on your browser is actually getting to the webserver.

Creating a local custom host name instead of localhost?

Currently, my flask app runs locally on:
http://localhost:5000/some_page
How could I create a local custom location for my app like:
http://myappname/some_page
Sort of like a local domain name. Is this possible at all? Any pointers would be great.
In order for the browser to resolve this custom name, you will need to add an alias to your /etc/hosts file. It probably already contains a line about 127.0.0.1, in which case you just add your alias to the list
127.0.0.1 localhost localhost.localdomain myappname
You can then change the server name in the app's config to make it explicitly use this name.
app.config['SERVER_NAME'] = 'myappname:5000'
Only privileged programs (run as root or with sudo) can bind to low ports such as 80, so you will still have to use a high port number.
It can be done using SERVER_NAME option in config:
app = Flask(__name__)
app.config['SERVER_NAME'] = 'myappname:80'
More information here:
http://flask.pocoo.org/docs/0.10/config/

Cannot forward to Openshift app (CNAME)

I have a domain registered with GoDaddy, let's call it xyz.com
Now I add a CNAME
Host: openshift
Points To: myapp-mynamespace.rhcloud.com
When I access openshift.xyz.com I only get:
Not Found
The requested URL /app was not found on this server.
Apache/2.2.15 (Red Hat) Server at openshift.xyz.com Port 443
Not sure why it tried to access /app at all, not sure if it actually did forward to Openshift app.
You should config Cname in Godday
Add alias in openshift:
Using command line :
rhc alias add YOUR_APP_NAME www.xyz.com
Hope it help you
That means that you do not have the alias setup on your application correctly on OpenShift, and the server does not know what application to map that domain name to. Make sure that you have added your custom domain to your OpenShift gear correctly. Also, if you are using example.com and www.example.com, make sure that you added them both. This blog post should help get you fixed up: https://www.openshift.com/blogs/custom-url-names-for-your-paas-applications-host-forwarding-and-cnames-the-openshift-way

Nginx and multiple domains

I bought some domains at godaddy.com (i.e mydomain.com) for my droplet at digitalocean.com (i.e 199.216.110.210). I run a nodejs application on port 80 on the droplet. From godaddy.com, I forward with masking mydomain.com to 199.216.110.210 and I could see may app.
Now I want to run on 199.216.110.210 several node applications on different ports, using ngnix as reverse proxy. I followed the instructions here (www.digitalocean.com/community/articles/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab).
My nginx .conf file is
server {
listen 80;
server_name mydomain.com;
location / {
proxy_pass http://localhost:3000;
# same as in the link above
}
}
(and I am sure it is read: when ngnix start if I put an error there, ngnix reports it).
I start the nodejs application on port 3000:
I try mydomain.com, but ngnix shows always the welcome page.
Also doing mydomain.com: 3000 does not work,
it works only with 199.216.110.210:3000.
From godaddy.com, if I forward with masking the mydomain.com to 199.216.110.210:3000 I can see may app.
But I do not like this solution. I would like domains pointing to my droplet, without specifing the port and admin them with nginx.
How can I get a domain name to use with ngnix as reverse proxy to select my apps, mapped on different domains on different ports? I suppose that forwarding from godaddy.com is somehow limited.
In your server go to /var/log/nginx and do a tail -F *log. Now in another shell restart nginx.
I suspect that your domain name is too long and nginx will complain about its hash_bucket_size is too small. If this is the case open /etc/nginx/nginx.conf and make sure that the line
server_names_hash_bucket_size 64;
exists, has a value of 64 and is uncommented. Then do sudo service nginx reload, and check if all works as expected.
I am going to detail step by step how I am able to do it in my aws ec2 instance;
I set up a DNS record to my instance, so i can set mydomain.com to 192.168.123.123 (my specific IP).
Inside my instance I have forever running my node.js app in port 3000 (I test it work by issuing curl localhost:3000 from the command line)
I then download this .sh file in order to properly intantiate nginx; curl -o nginxStarter.sh https://gist.githubusercontent.com/renatoargh/dda1fbc854f7957ec7b3/raw/c0bc1a1ec76e50cdb4336182c53a0b222edb6c0e/start.sh
I configure nginx with this configuration file. Put this file in; /etc/nginx/nginx.conf
Start nginx with this command; sudo sh nginxStarter.sh start
PS.: For multiple apps just replicate the lines that routes the requests to specific ports, very easy...! If not needed you can eliminate lines regarding out SSL.

Assigning a domain name to localhost for development environment

I am building a website and would not like to reconfigure the website from pointing to http://127.0.0.1 to http://www.example.com. Furthermore, the certificate that I am using is of course made with the proper domain name of www.example.com but my test environment makes calls to 127.0.0.1 which makes the security not work properly.
What I currently want to do is configure my development environment to assign the domain name www.example.com to 127.0.0.1 so that all http://www.example.com/xyz is routed to http://127.0.0.1:8000/xyz and https://www.example.com/xyz is routed to https://127.0.0.1:8080/xyz.
I am not using Apache. I am currently using node.js as my web server and my development environment is in Mac OS X Lion.
If you edit your etc/hosts file you can assign an arbitrary host name to be set to 127.0.0.1.
Open up /etc/hosts in your favorite text editor and add this line:
127.0.0.1 www.example.com
Unsure of how to avoid specifying the port in the HTTP requests you make to example.com, but if you must avoid specifying that at the request level, you could run nodejs as root to make it listen on port 80.
Edit: After editing /etc/hosts, you may already have the DNS request for that domain cached. You can clear the cached entry by running this on the command line.
dscacheutil -flushcache

Resources