morph1904 / Tyger2

A Reverse Proxy Application
GNU General Public License v2.0
51 stars 11 forks source link

Unablet to login 502 error on AJAX request #31

Closed morph1904 closed 3 years ago

morph1904 commented 3 years ago

I have the exact same issue but with the current docker beta image. Any idea what is wrong with my setting? (Except of not internet accessible)

Within my Firefox I get a bunch of "cross-site access not allowed source: https://fonts.gstatic.com..." and so no images at login screen. Trying to log in gets me only the "XHR POST http://server.lab.domain.net:7071/api/api-token-auth/ [HTTP/1.1 502 Bad Gateway 28ms]"

My portainer setting:

version: "2.4"                                                                                                          
services: 
  Tyger2Beta:
    image: morph1904/tyger2:beta
    container_name: tyger2beta
    volumes:
      - tyger2beta_data:/apps/Tyger2/data
      - tyger2beta_certs:/root/.caddy
    ports:
      - 443:443
      - 80:80
      - 7070:9090
      - 7071:9091
    restart: unless-stopped

Portainer log:

Operations to perform:,
  Apply all migrations: addresses, admin, apps, auth, contenttypes, dns, endpoints, install, sessions,
Running migrations:,
  No migrations to apply.,
  Your models have changes that are not yet reflected in a migration, and so won't be applied.,
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.,
Looks installed, doing nothing,
Creating uwsgi.log,
Creating uwsgi-access.log,
*** Starting uWSGI 2.0.19.1 (64bit) on [Fri Oct  9 01:34:40 2020] ***,
compiled with version: 9.3.0 on 01 October 2020 13:57:47,
os: Linux-4.19.0-11-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17),
nodename: 440f96a69d03,
machine: x86_64,
clock source: unix,
detected number of CPU cores: 8,
current working directory: /,
detected binary path: /usr/local/bin/uwsgi,
!!! no internal routing support, rebuild with pcre support !!!,
uWSGI running as root, you can use --uid/--gid/--chroot options,
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** ,
*** WARNING: you are running uWSGI without its master process manager ***,
your memory page size is 4096 bytes,
detected max file descriptor number: 1048576,
*** starting uWSGI Emperor ***,
Starting ServicesActivating privacy features... done.,
,
Serving HTTP on port 9091 ,
http://:9091/api,

BTW: the logo is very similar to "Syncthing" is that on purpose?

_Originally posted by @BlackF09 in https://github.com/morph1904/Tyger2/issue_comments/705918521_

morph1904 commented 3 years ago

Hi There.

It is almost definite that you are getting this issue because of this error:

http://server.lab.domain.net:7071/api/api-token-auth/ [HTTP/1.1 502 Bad Gateway 28ms]"

When you completed the installation form, did you enter server.lab.domain.net or the IP of your docker host?

It should look something like this: image

BlackF09 commented 3 years ago

I tried the hosts IP and the internal bridge network IP (172.17. 0.x) both with the same results. My browser came from the hosts network via my desktop machine (192.168.1.y).

morph1904 commented 3 years ago

Hi.

The IP in the set up needs to be the hosts IP address and not the bridge network. Also please make sure that the port is open on the OS.

I would recommend deleting your mapped data (so Tyger does not know it has been previously installed) and trying again.

Another thing you can try is to access the api before completing the installer. Run your container and visit http://192.168.1.Y:7071/api and see what loads. You can also CURL it if that is better for you.

The basics of what is happening here is that the IP address of your host is set on the installer so that the frontend can forward requests to it. You are unable to log on because that request is not getting through.

BlackF09 commented 3 years ago

No luck! However @ http://192.168.a.b:7070/admin/ I got a "Django administration" page. Google said I should create an superuser, Django said "You have 32 unapplied migration(s)", so I did that and could then create a superuser. I could even log in (without any eye-candy, no .css and .js files could be loaded) and click around. Everything else is "bad gateway" (incl. /api), from my PC, host & inside container with the set IP or other IP, before and after installation.

Does it matter that my docker host has two IP addresses set at host network because it was migrated?

morph1904 commented 3 years ago

I think we need to take a look at your caddyfile can you post it here please? It will be in your mapped data directory. The 502 bad gateway message is thrown by caddy which proxies the backend by default. It means that caddy cannot connect to uwsgi.

BlackF09 commented 3 years ago

Nothing special I would say. caddyfile.conf:

:9091/api {
        proxy / localhost:9090 {
                transparent
        }
 }
 :9091 {
         root /apps/Tyger2/frontend/dist
         log /apps/Tyger2/data/logs/frontend.log
         rewrite {
                 regexp .*
                 to {path} /
         }
 }
morph1904 commented 3 years ago

Yup there is the issue.

If you see above, caddy is expecting requests to the api on port 9091 but you are sending them on port 7071. You can try manually changing the caddyfile, or map port 9091 instead and it will start working.

BlackF09 commented 3 years ago

I'm confused, port 7070 & 7071 are my mapped ports within docker...

Everything below I tested multiple times even with the chromium edge browser and always with hosts IP eg 192.168.123.123 and 192.168.124.124. I did change the caddyfile and my portainer stack to point everything to 7070 & 7071. URL Response
:7070/install "connection refused"
:7071/api "502 Bad Gateway"
:7071/login Login site w/o Icons and login with "502 Bad Gateway" for :7071/api/api-token-auth/

No database file ofc

So I freed port 9090 & 9091 (prometheus), deleted data and changed everything back to 9090 & 9091: URL Response
:9090/install Setup page
:9091/api "502 Bad Gateway"
:9091/login Login site w/o Icons and login with "502 Bad Gateway" for :9091/api/api-token-auth/

Same as last one goes for docker mapped ports from 6060 & 6061 -> 9090 & 9091.

I'm sorry, I have no clue what is so different with my docker/network environment (except from my two IP's at one eth0) then with others. Most things do work for me and it's ok if it is not solvable. We are all here in our spare time.

Anything more "aggressive" debug logging possible?

BlackF09 commented 3 years ago

Got it! First I tested at caddyfile.conf with a dedicated IP address, because I have two configured:

192.168.a.b:9091/api {
        proxy / localhost:9090 {
                transparent
        }
 }
192.168.a.b:9091 {
         root /apps/Tyger2/frontend/dist
         log /apps/Tyger2/data/logs/frontend.log
         rewrite {
                 regexp .*
                 to {path} /
         }
 }

With the success of getting at login the icons of the face and lock instead of the words face and login, but still "bad gateway" for login. Strangely the icons stayed after removing the IP...

After that I just guessed that something with localhost could be strange for your web frontend:

root@host:/# ping localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.047 ms
64 bytes from localhost (::1): icmp_seq=2 ttl=64 time=0.029 ms
64 bytes from localhost (::1): icmp_seq=3 ttl=64 time=0.028 ms

So, could IPv6 be the problem? Yes it is! I changed "loalhost" to the local IP "127.0.0.1" and it works! :D

From now on I get from time to time "bad gateway" for "stats" and "api-token-refresh" and now again for "api-token-auth" at login....

morph1904 commented 3 years ago

The latest release of TygerCaddy does not use this method to map to the backend. so this should not be an issue. I will leave this issue open untill the new version is released.