Error 502 Bad Gateway


Hi there,

I’ve installed funkwhale using Docker on a Ubuntu 18.04 server.

I was already running docker and am using a Letsencrypt nginx container for my reverse proxies, I’m also using cloudflare.

I can access the homepage, and I see the correct lay-out but in my console I get:

and I can’t access the login page.

Any ideas what might be happening?

I’m using the following reverse proxy config:

upstream fw {
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;

server {
    listen 443 ssl;

    server_name funkwhale.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
        include /config/nginx/proxy.conf;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass   http://fw/;

My .env:




The 502 error either indicate:

  1. that your reverse proxy is pointing to the wrong place (wrong port or IP)
  2. that Funkwhale’s nginx container is down
  3. That Funkwhale’s api container is down

Can you confirm that there is something listening on on your host (netstat -tlpn), and check in the logs of the api and nginx container while you’re doing a request (docker-compose logs -f --tail=50 nginx api) ?



netstat -tlpn shows:

docker-compose ps shows:

so it’s probably the API port that’s wrong?

The thing is, I can’t use port 5000, since it’s already used by the synology NAS.

What ports should I be using for API and NGINX?


Hm based on your netstat output, it looks like the process listen on ipv6 only, which could cause the issue, since your nginx conf points to a ipv4 address. It looks like you edited the default compose file, because the nginx container is normally listening on the FUNKWHALE_API_PORT from your .env file:

      # override those variables in your .env file if needed

Does putting that instead then relaunching your containers fix the issue ?


Ok, I’ve changed the default back.

So about the netstat output, I doubt that’s an issue:

When setting up the proxy, Docker requests the loopback address ‘’, Linux realises this is an address that exists in IPv6 (as ::0) and opens on both (but it is formally an IPv6 socket). When you run netstat it sees this and tells you it is an IPv6 - but it is still listening on IPv4.

When doing docker-compose logs -f --tail=50 nginx api:

and then when I visit my domain, I get:
2018/12/07 15:17:25 [error] 14#14: *9 connect() failed (111: Connection refused) while connecting to upstream, client:, server: funkwhale.domain.tld, request: "GET /api/v1/instance/settings/ HTTP/1.1", upstream: "", host: "funkwhale.domain.tld:443", referrer: "https://funkwhale.domain.tld/"


Is it normal that you have in the upstream IP, while you have FUNKWHALE_API_IP= in your .env? I’d say both values should match.


No, I don’t think it’s normal. But I’m not sure where the NGINX docker gets it from.

Nvm, changed the value to getting a lot more output now:

Getting like 10 of the above messages when I visit now, but still some errors in the console:

The nginx logs look like some sort of redirect loop:


Changing the API IP and port fixed the errors, however, when trying to create an account, the loading spinner keeps loading:


Can you visit http://yourdomain/api/admin and log in with the credentials you gave when creating your superuser?


Unable to access it, 504 Gateway Time-out.

Also getting the error: Invalid HTTP_HOST header: ‘’. You may need to add ‘’ to ALLOWED_HOSTS.

When visiting the IP myself.


You may have to add your ip in the DJANGO_ALLOWED_HOSTS field (values separated with commas) in your .env file.


Thanks, changed some things and everything seems to work. However, when logging in:

api_1 | 2018-12-08 00:06:31,953 ERROR Internal Server Error: /api/v1/playlists/
api_1 | Traceback (most recent call last):
api_1 | File “/usr/local/lib/python3.6/site-packages/django/db/backends/”, line 85, in _execute
api_1 | return self.cursor.execute(sql, params)
api_1 | psycopg2.IntegrityError: duplicate key value violates unique constraint “federation_actor_url_key”
api_1 | DETAIL: Key (fid)=(https://funkwhale.domain.tld/federation/actors/username) already exists.

Can I ignore this error?

Edit: Also, I see that it’s possible to import files, however, is it possible to sync certain folders? Or would I just need to run the import_files every once in a while?


@GriffinSC you can get rid of this error by visiting /api/admin/federation/actor and deleting the object matching the one in the error (you probably only have one object anyway).

No, there is no way to do that, you will have to setup a cron job to do this for you on a regular basis :slight_smile:

closed #14