1
votes

I'm trying to run a web server using a virtual machine using Google Compute Engine and Dokku.

What I did:

  • I created a virtual machine (instance) using Google Compute Engine
  • I enabled the TCP:80 port to allow incoming connection for web apps
  • I installed Dokku inside the virtual machine
  • I deployed my web app using git push dokku master
  • The server is running ok (I've checked the logs using dokku logs myapp

However, I can't access it using the external ip address of the instance

I think it is a problem with the nginx

1
Looks like a problem of system administration, not software development, so you may get help asking this Q over at serverfault.com, rather than here -- we do monitor the google-compute-engine tag there, too... - Alex Martelli
I suggest to check if your instance listens to port 80 locally. You would also want to check if it binds to the instance IP address or just on localhost eg. telnet localhost 80 telnet instance-ip 80 can you please confirm that the later test succeeds, if not you probably need to change your configuration to extend the network interfaces the processes bind to - Feczo

1 Answers

1
votes

I've changed the default nginx.conf inside of the /home/dokku//

for this one:

upstream $APP-domains { server $INTERNAL_IP:$PORT; }
server {
  listen        [::]:80;
  listen        80;
  server_name   $EXTERNAL_IP;

  location / {
    proxy_pass http://$APP-domains; 
    proxy_http_version 1.1;
    proxy_set_header Upgrade $$http_upgrade;
    proxy_set_header Connection upgrade;
    proxy_set_header Host $$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;
    proxy_cache_bypass $$http_upgrade;
  }
 }

where $APP, $PORT, $INTERNAL_IP, $EXTERNAL_IP should change based on the dokku app deployed.

$PORT = /home/dokku//PORT

$INTERNAL_IP = /home/dokku//IP

$APP = app_name

$EXTERNAL_IP = your public IP

After change the nginx.conf inside of the app location, you should restart NGINX (sudo service nginx restart)

This is a python gist using fabric to handle this process:

@task
def config_vhost(ip, app):
    """Use the nginx template to redirect app to port 80"""
    port = run('cat /home/dokku/{}/PORT'.format(app))
    internal_ip = run('cat /home/dokku/{}/IP'.format(app))

    values = {'EXTERNAL_IP': ip, 'INTERNAL_IP': internal_ip, 'PORT': port, 'APP': app}

    nginx = open(NGINX_TEMPLATE, 'r').read()
    nginx_template = string.Template(nginx)

    nginx_conf = nginx_template.substitute(values)
    sudo("echo '{}' > /home/dokku/{}/nginx.conf".format(nginx_conf, app))
    sudo("service nginx restart")