http 405 error in frontend when running with traefik v2 and docker #1708

Closed
opened 2020-02-28 19:48:05 +00:00 by adrinux · 13 comments

No matter what I try in my docker-compose I seem to end up with a 405 error on the front end.

I can reach the frontend, fill out the register form but on submission there is a brief flash of 'loading' and nothing else happens.

Checking the logs for the frontend container I see:


redacted_ip - - [28/Feb/2020:19:26:38 +0000] "POST /api/v1/register HTTP/1.1" 405 157 "http://vikunja.example.com:10110/register" "Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0" "-"

405 is "Method Not Allowed"

As far as I can tell this means that the request is reaching the backend but the backend is refusing to answer for some reason.

The logs on the backend container don't show anything special


2020-02-28T19:20:09.782900293Z: INFO	▶ migration/Migrate 002 [Ran all migrations successfully.]
2020-02-28T19:20:09.783088575Z: INFO	▶ cmd/func1 003 Vikunja version 0.10+24-88bf8f3df0
⇨ http server started on [::]:3456
No matter what I try in my docker-compose I seem to end up with a 405 error on the front end. I can reach the frontend, fill out the register form but on submission there is a brief flash of 'loading' and nothing else happens. Checking the logs for the frontend container I see: ``` redacted_ip - - [28/Feb/2020:19:26:38 +0000] "POST /api/v1/register HTTP/1.1" 405 157 "http://vikunja.example.com:10110/register" "Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0" "-" ``` 405 is "Method Not Allowed" As far as I can tell this means that the request is reaching the backend but the backend is refusing to answer for some reason. The logs on the backend container don't show anything special ``` 2020-02-28T19:20:09.782900293Z: INFO ▶ migration/Migrate 002 [Ran all migrations successfully.] 2020-02-28T19:20:09.783088575Z: INFO ▶ cmd/func1 003 Vikunja version 0.10+24-88bf8f3df0 ⇨ http server started on [::]:3456 ```
Owner

Can you reach the info endpoint on the backend?

Try running

curl http://your-vikunja-url.com/api/v1/info

Are you using the traefik example from the docs?

Can you reach the info endpoint on the backend? Try running ``` curl http://your-vikunja-url.com/api/v1/info ``` Are you using [the traefik example from the docs](https://vikunja.io/docs/full-docker-example/#example-with-traefik)?
Author

If I include the port number I defined in my docker-compose:

curl http://your-vikunja-url.com:10110/api/v1/info

I get "We're sorry but Vikunja doesn't work properly without JavaScript enabled" etc.

Which doesn't seem llike 'info'? Visiting that url in the browser gives a TypeError "navigator.serviceWorker is undefined". Actually I get that error on the login and register pages too...

I'm using traefik v2, so not exactly the the example from the docs, no. A conversion of it, also not quite the same as the one given on reddit

I'm adding it to a stack with traefik, portainer and kanboard already present.

Edit: I think the issue may well be in my docker/traefik config. Don't seem to be serving via https correctly.

If I include the port number I defined in my docker-compose: ``` curl http://your-vikunja-url.com:10110/api/v1/info ``` I get "We're sorry but Vikunja doesn't work properly without JavaScript enabled" etc. Which doesn't seem llike 'info'? Visiting that url in the browser gives a TypeError "navigator.serviceWorker is undefined". Actually I get that error on the login and register pages too... I'm using traefik v2, so not exactly the the example from the docs, no. A conversion of it, also not quite the same as the one given [on reddit](https://www.reddit.com/r/selfhosted/comments/f3d4y9/vikunja_the_todo_app_to_organize_your_life/fhknzb7?utm_source=share&utm_medium=web2x) I'm adding it to a stack with traefik, portainer and kanboard already present. Edit: I think the issue may well be in my docker/traefik config. Don't seem to be serving via https correctly.
Owner

Could you post your traefik config?

It seems this might be a race condition where the frontend starts faster than the back end and so traefik uses it prefferrably.

Could you post your traefik config? It seems this might be a race condition where the frontend starts faster than the back end and so traefik uses it prefferrably.
Author

I experimented with only starting the backend - no response with curl until I added ports "3456:3456", which makes sense.

Then get a response on:

curl http://your-vikunja-url.com:3456/api/v1/info

of

{"version":"0.10+24-88bf8f3df0","frontend_url":"","motd":"","link_sharing_enabled":true,"max_file_size":"20MB","registration_enabled":true,"available_migrators":null,"task_attachments_enabled":true}

Obviously curl wasn't going to get a response without the backend allowing connection to the outside world? Does the frontend need that too though? I'd assumed the back and front end being on the same 'backend' docker network would be enough...

Still can't register or login once the frontend is started.
I also don't have fully functioning https yet.

Attaching a sanitized docker-compose.yml and the two jinja2 templates I have ansible copy into place for traefik config - mostly just vars for domain name etc. I hope their clear enough.

I experimented with only starting the backend - no response with curl until I added ports "3456:3456", which makes sense. Then get a response on: ``` curl http://your-vikunja-url.com:3456/api/v1/info ``` of ``` {"version":"0.10+24-88bf8f3df0","frontend_url":"","motd":"","link_sharing_enabled":true,"max_file_size":"20MB","registration_enabled":true,"available_migrators":null,"task_attachments_enabled":true} ``` Obviously curl wasn't going to get a response without the backend allowing connection to the outside world? Does the frontend need that too though? I'd assumed the back and front end being on the same 'backend' docker network would be enough... Still can't register or login once the frontend is started. I also don't have fully functioning https yet. Attaching a sanitized docker-compose.yml and the two jinja2 templates I have ansible copy into place for traefik config - mostly just vars for domain name etc. I hope their clear enough.
Owner

The requests from the frontend to the backend happen in the browser, so the backend must be reachable from the outside world.

The frontend assumes the backend on /api/v1 of the same host.

Since you're using traefik, you should not need to expose ports of both containers, traefik should handle that.
In your example, you should be able to use Vikunja from vikunja.app.example.com (aka get the frontend if you visit vikunja.app.example.com directly in your browser).

You can verify the routing of the backend is working correctly by running

curl https://vikunja.app.example.com/api/v1

(should return the info response you posted earlier)

The requests from the frontend to the backend happen in the browser, so the backend must be reachable from the outside world. The frontend assumes the backend on `/api/v1` of the same host. Since you're using traefik, you should not need to expose ports of both containers, traefik should handle that. In your example, you should be able to use Vikunja from `vikunja.app.example.com` (aka get the frontend if you visit `vikunja.app.example.com` directly in your browser). You can verify the routing of the backend is working correctly by running ``` curl https://vikunja.app.example.com/api/v1 ``` (should return the info response you posted earlier)
Author

I've been able to remove the ports declarations yes - since I already have kanboard on a different port vikunja can use 80/443 (but not specifying a port for multiple services which run on 80 or 443 results in an error when running 'docker-compose up': "port is already allocated").

Still haven't been able to get things functioning though.

Might bring down my whole stack and try with some of the example compose files alone. About ready to throw in the towel though. I don't think it's vikunja's fault so much as my inexperience with docker and traefik.

I've been able to remove the ports declarations yes - since I already have kanboard on a different port vikunja can use 80/443 (but not specifying a port for multiple services which run on 80 or 443 results in an error when running 'docker-compose up': "port is already allocated"). Still haven't been able to get things functioning though. Might bring down my whole stack and try with some of the example compose files alone. About ready to throw in the towel though. I don't think it's vikunja's fault so much as my inexperience with docker and traefik.
Owner

Do you see the vikunja containers in the traefik backend?

I'll try to put out an example docker-compose configuration with traefik v2 soon, maybe that will work...

I’ve been able to remove the ports declarations yes - since I already have kanboard on a different port vikunja can use 80/443 (but not specifying a port for multiple services which run on 80 or 443 results in an error when running ‘docker-compose up’: “port is already allocated”).

This would make sense since traefik already uses these ports to communicate from the outside world.

You also have traefik.http.services.vikunja-backend.loadbalancer.server.port in your traefik config, normally you should not need that. Traefik is able to figure out what ports the vikunja docker image exposes and redirect the traffic to that. That should not be an issue here though.

You also seem to put the vikunja docker containers in the web network, but if I saw that correctly you're never telling traefik to use that network. This may still work though because you have all containers in a single docker-compose file which lets them see each other by default.

Did you try increasing the log level of traefik to debug to see if it logs anything useful?

Do you see the vikunja containers in the traefik backend? I'll try to put out an example docker-compose configuration with traefik v2 soon, maybe that will work... > I’ve been able to remove the ports declarations yes - since I already have kanboard on a different port vikunja can use 80/443 (but not specifying a port for multiple services which run on 80 or 443 results in an error when running ‘docker-compose up’: “port is already allocated”). This would make sense since traefik already uses these ports to communicate from the outside world. You also have `traefik.http.services.vikunja-backend.loadbalancer.server.port` in your traefik config, normally you should not need that. Traefik is able to figure out what ports the vikunja docker image exposes and redirect the traffic to that. That should not be an issue here though. You also seem to put the vikunja docker containers in the `web` network, but if I saw that correctly you're never telling traefik to use that network. This may still work though because you have all containers in a single docker-compose file which lets them see each other by default. Did you try increasing the log level of traefik to `debug` to see if it logs anything useful?
Author

More progress, somewhat shame faced, realised the the host firewall was blocking access. That's why I setting ports in the docker-compse seemed to be required - it makes docker create firewawll rules in its own iptables chain bypassing the host chains.

I've slimmed down my compose file a bit more removing the loadbalancer lines as you suggested. Also removed most of the 'ports' declarations and reworked the 'networks' declarations.

Traefik debug logs don't seem to show anything else useful.

But I have been able to create an account it vikunja and log in. Unfortunetly I get '404 page not found' errors that prevent vikunja from working properly (no sidebar menu?). My kanboard container also gives '404 page not found' so clearly still have something not quite right in this stack.

Still investigating the 404 errors.

More progress, somewhat **shame faced**, realised the the host firewall was blocking access. That's why I setting ports in the docker-compse seemed to be required - it makes docker create firewawll rules in its own iptables chain bypassing the host chains. I've slimmed down my compose file a bit more removing the loadbalancer lines as you suggested. Also removed most of the 'ports' declarations and reworked the 'networks' declarations. Traefik debug logs don't seem to show anything else useful. *But* I have been able to create an account it vikunja and log in. Unfortunetly I get '404 page not found' errors that prevent vikunja from working properly (no sidebar menu?). My kanboard container also gives '404 page not found' so clearly still have something not quite right in this stack. Still investigating the 404 errors.
Author

The kanboard 404 errors turned out to be due to a typo in my traefik labels. The vikunja 404 errors not so.

Testing the api with curl I get, using http url:

curl http://vikunja.app.example.com/api/v1/info
404 page not found

and with https url:

curl https://vikunja.app.example.com/api/v1/info
{"version":"0.11+4-7de26a462f","frontend_url":"vikunja.app.example.com","motd":"","link_sharing_enabled":true,"max_file_size":"20MB","registration_enabled":true,"available_migrators":null,"task_attachments_enabled":true}

So it appears that the frontend wants to reach the api on http but traefik is only routing over https as I have it configured.

edit: sanitised docker-compose.yml attached

The kanboard 404 errors turned out to be due to a typo in my traefik labels. The vikunja 404 errors not so. Testing the api with curl I get, using http url: ``` curl http://vikunja.app.example.com/api/v1/info 404 page not found ``` and with https url: ``` curl https://vikunja.app.example.com/api/v1/info {"version":"0.11+4-7de26a462f","frontend_url":"vikunja.app.example.com","motd":"","link_sharing_enabled":true,"max_file_size":"20MB","registration_enabled":true,"available_migrators":null,"task_attachments_enabled":true} ``` So it appears that the frontend wants to reach the api on http but traefik is only routing over https as I have it configured. edit: sanitised docker-compose.yml attached
Author

Found an the error in the api container logs for the 404 - maybe it is routing ok

2020-03-04T15:53:06.175290824Z: WEB 	▶ IPADDRESS  GET 404 /api/v1/[object%20Object]?sort_by[]=due_date_unix&sort_by[]=id&order_by[]=desc&order_by[]=desc&page=1 48.707µs - Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0
Found an the error in the api container logs for the 404 - maybe it is routing ok ``` 2020-03-04T15:53:06.175290824Z: WEB ▶ IPADDRESS GET 404 /api/v1/[object%20Object]?sort_by[]=due_date_unix&sort_by[]=id&order_by[]=desc&order_by[]=desc&page=1 48.707µs - Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0 ```
Author

I don't know what I changed - possibly just adding https to the start of the frontendurl environment variable - created a second account using Chrome instead of Firefox and it worked! Also then worked in Firefox after a browser reload.

Fixed!

I don't know what I changed - possibly just adding https to the start of the frontendurl environment variable - created a second account using Chrome instead of Firefox and it worked! Also then worked in Firefox after a browser reload. Fixed!
Owner

The sympthomes you described were a bug in the frontend which I've fixed in fe6c859150.

Glad it works now!

The sympthomes you described were a bug in the frontend which I've fixed in https://kolaente.dev/vikunja/frontend/commit/fe6c85915072437b81f36f26e8a0ab58d399754c. Glad it works now!
Author

I think this can be closed.

I think this can be closed.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: vikunja/vikunja#1708
No description provided.