dokku / dokku-redirect

A plugin for dokku that gives the ability to set simple redirects for an application
MIT License
106 stars 9 forks source link

[emerg] invalid port in "[::]:" of the "listen" directive #3

Closed julienma closed 8 years ago

julienma commented 8 years ago

I successfully used this plugin on Dokku 0.4.14.

Now, I've updated straight to Dokku 0.5.3, which works fine. However, when I try to set a new redirect, I have this error:

 ~ dokku redirect:set myapp app.com www.app.com
-----> Setting redirect for myapp...
-----> Configuring myapp...(using built-in template)
-----> Configuring www.app.com...(using built-in template)
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
-----> Configuring redirect for app.com to www.app.com...
       Reloading nginx
nginx: [emerg] invalid port in "[::]:" of the "listen" directive in /home/dokku/myapp/nginx.conf:40
nginx: configuration file /etc/nginx/nginx.conf test failed

www.myapp.com is a domain already assigned to myapp; myapp.com isn't.

Here's the bit of content which has been added at the end of /home/dokku/myapp/nginx.conf after running the above (failed) command:

server {
  listen      [::]:;
  listen      ;
  server_name app.com;
  return 301 $scheme://www.app.com$request_uri;
}

=> It seems the port is not set?

Flink commented 8 years ago

This is related to the new template system I guess, I’ll try to fix this ASAP.

Flink commented 8 years ago

Hmm that’s weird I don’t have the problem (tried on 2 machines). I’ll have to investigate.

josegonzalez commented 8 years ago

Are you on a host with ipv6?

julienma commented 8 years ago

Nop, no ipv6. This app does have a custom Dockerfile and nginx.conf (see content below), but I have the same error on another app which uses a buildpack.

Dockerfile:

FROM debian

RUN apt-get update && \
    apt-get install -y nginx-light && \
    rm -rf /var/lib/apt/lists/*

RUN mkdir /app
ADD . /app

EXPOSE 80

CMD ["nginx", "-c", "/app/.nginx.conf"]

.nginx.conf:

daemon off;
error_log stderr;
worker_processes 1;

events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log /dev/stdout;

    server {
        listen 80;
        port_in_redirect off;

        location / {
            root "/app/dist";
            autoindex
                on;
            index
                index.html
                index.htm;
        }
    }
}
josegonzalez commented 8 years ago

Can you gist the logs from a deploy after doing:

dokku trace on
julienma commented 8 years ago

@josegonzalez here's the log after pushing to my dokku remote: https://gist.github.com/julienma/e311a84bd4a3c48e2ac87e94ed5aef72

josegonzalez commented 8 years ago

@Flink I think NGINX_PORT and DOMAIN may not be being populated here: https://github.com/dokku/dokku-redirect/blob/master/templates/redirect.conf

Flink commented 8 years ago

@josegonzalez yeah it seems so but on two different servers I don’t have the bug, that’s weird.

Flink commented 8 years ago

Ho wait, I didn’t see this was a Dockerfile, I’ll have to check, it might explain the problem.

Flink commented 8 years ago

@julienma Could you copy/paste the complete nginx.conf generated by dokku please?

julienma commented 8 years ago

@Flink here's /home/dokku/myapp.fr/nginx.conf before adding the redirect:

server {
  listen      [::]:80;
  listen      80;
  server_name myapp.fr www.app.com;
  access_log  /var/log/nginx/myapp.fr-access.log;
  error_log   /var/log/nginx/myapp.fr-error.log;

  location    / {

    gzip on;
    gzip_min_length  1100;
    gzip_buffers  4 32k;
    gzip_types    text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json appl$
    gzip_vary on;
    gzip_comp_level  6;

    proxy_pass  http://myapp.fr-80;
    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;
  }
}
include /home/dokku/myapp.fr/nginx.conf.d/*.conf;

upstream myapp.fr-80 {
  server 172.17.0.4:80;
}

Same file, after running dokku redirect:set myapp.fr app.com www.app.com

server {
  listen      [::]:80;
  listen      80;
  server_name myapp.fr www.app.com;
  access_log  /var/log/nginx/myapp.fr-access.log;
  error_log   /var/log/nginx/myapp.fr-error.log;

  location    / {

    gzip on;
    gzip_min_length  1100;
    gzip_buffers  4 32k;
    gzip_types    text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json appl$
    gzip_vary on;
    gzip_comp_level  6;

    proxy_pass  http://myapp.fr-80;
    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;
  }
}
include /home/dokku/myapp.fr/nginx.conf.d/*.conf;

upstream myapp.fr-80 {
  server 172.17.0.4:80;
}

server {
  listen      [::]:;
  listen      ;
  server_name app.com;
  return 301 $scheme://www.app.com$request_uri;
}

(I've replaced the real domains with fake ones. For the sake of clarity, my dokku app is named like app.fr, I've added to it another domain www.app.com, and I'd like to add a redirect from app.com to www.app.com, which means it could be accessed through 3 different domains).

marvinroger commented 8 years ago

I don't have this problem either, with buildpacks.

julienma commented 8 years ago

FYI, I've updated to Dokku 0.5.5, and still have this issue, only with a Dockerfile though, as it works fine with a (PHP) Buildpack.

michaelshobbs commented 8 years ago

I think that's because NGINX_SSL_PORT and NGINX_PORT are not defined in all dockerfile instances. Try setting those and report back?

julienma commented 8 years ago

I'll need a bit more help, as I'm not sure what to do.

The only resource I found regarding NGINX_PORT is this page: http://dokku.viewdocs.io/dokku~v0.5.5/nginx/ (there's also something about docker-compose, but I don't use that). You want me to create an nginx.conf.sigil along my Dockerfile?

michaelshobbs commented 8 years ago

No worries. Do this instead and share the output here.

$ dokku config $APP | grep DOKKU_NGINX
julienma commented 8 years ago

Output is empty.

To make sure, I did the same with an app (using Buildpack) for which redirect works, and I got this:

DOKKU_NGINX_PORT:  80
michaelshobbs commented 8 years ago

Can you share your Dockerfile?

julienma commented 8 years ago

Sure, that's the one posted above: https://github.com/dokku/dokku-redirect/issues/3#issuecomment-203711633

michaelshobbs commented 8 years ago

Ah my bad. Reading on mobile atm

michaelshobbs commented 8 years ago

Try removing EXPOSE 80 from Dockerfile and changing listen 80; to listen 5000; in .nginf.conf

michaelshobbs commented 8 years ago

If you don't want to do that, you can set DOKKU_NGINX_PORT=80 using the dokku config:set command.

michaelshobbs commented 8 years ago

Let us know what you find out

julienma commented 8 years ago

So I tried:

1. removing EXPOSE 80 from Dockerfile and changing listen 80; to listen 5000; in .nginf.conf

Changed this, pushed / deployed, then set redirect. Got same error:

 ~ dokku redirect:set myapp app.com www.app.com
-----> Setting redirect for myapp...
-----> Configuring myapp...(using built-in template)
-----> Configuring www.app.com...(using built-in template)
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
-----> Configuring redirect for app.com to www.app.com...
       Reloading nginx
nginx: [emerg] invalid port in "[::]:" of the "listen" directive in /home/dokku/myapp/nginx.conf:40
nginx: configuration file /etc/nginx/nginx.conf test failed

2. set DOKKU_NGINX_PORT=80 using the dokku config:set command.

I reverted the 1st step, and did:

dokku config:set myapp DOKKU_NGINX_PORT=80

After a ps:restart, the dokku redirect:set myapp app.com www.app.com works fine, and the redirection actually works.

So that's one way to solve this, thanks. However, I'd like to avoid setting that DOKKU_NGINX_PORT var manually for all my project. Is there any way to solve this through the Dockerfile and / or nginx.conf instead?

Thanks!

michaelshobbs commented 8 years ago

Ah! I think the first on failed because of some leftovers from the original deployment. Soooooo, modify your app repo as mentioned previously. Then destroy the app using dokku apps:destroy and push it again. That should work from a fresh app push.

michaelshobbs commented 8 years ago

@josegonzalez This plugin will need to either be updated to support Dockerfile apps with EXPOSE ports or we say this only works with buildpack apps and Dockerfile apps that don't use EXPOSE.

julienma commented 8 years ago

@michaelshobbs yeaaah you're right, after destroying the app and pushing again, this worked fine!

removing EXPOSE 80 from Dockerfile and changing listen 80; to listen 5000; in .nginf.conf

I'll update my other Dockerfiles. Many thanks!