I'm trying to run a web server using a virtual machine using Google Compute Engine and Dokku.
What I did:
However, I can't access it using the external ip address of the instance
I think it is a problem with the nginx
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.