souramoo / commentoplusplus

Commento with out of the box patches and updates to add useful features and fixes. Also with one-click deploy to Heroku so you can get up and running fast.
MIT License
389 stars 62 forks source link

Commento doesn't acknowledge any requests #120

Closed sander1095 closed 2 years ago

sander1095 commented 2 years ago

Hi!

I created #119 earlier, but like I commented there, when i clone the project and run docker compose, the project actually starts and the port binds, etc.. No errors whatsoever.

To recap: I run on a raspberry pi 3b+.

But, I can't actually get my requests to work. I don't know what I am doing wrong, and I'm pulling my hairs out.

The containers start up and the server says it's listening on 0.0.0.0:8080. When I send a curl from my Pi request to that address, the server responds with a permanent redirect to https://commento.website.lol/login. (COMMENTO_ORIGIN + /login, basically)

2022/08/19 18:12:53 [INFO] version.go:12 versionPrint(): starting Commento
2022/08/19 18:12:53 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2022/08/19 18:12:53 [INFO] database_migrate.go:47 migrateFromDir(): 33 migrations already installed, looking for more
2022/08/19 18:12:53 [INFO] database_migrate.go:91 migrateFromDir(): none found
2022/08/19 18:12:53 [WARNING] smtp_configure.go:15 smtpConfigure(): smtp not configured, no emails will be sent
2022/08/19 18:12:53 [INFO] smtp_templates.go:43 smtpTemplatesLoad(): loading templates: [confirm-hex reset-hex domain-export domain-export-error]
2022/08/19 18:12:53 [INFO] sigint.go:22 sigintCleanupSetup(): setting up SIGINT cleanup
2022/08/19 18:12:53 [INFO] router.go:52 routesServe(): starting server on 0.0.0.0:8080
2022/08/19 18:12:54 [INFO] version.go:54 func1(): New update available! Latest version: v1.8.7
2022/08/19 19:46:55 [INFO] version.go:12 versionPrint(): starting Commento
2022/08/19 19:46:55 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2022/08/19 19:46:55 [INFO] database_migrate.go:47 migrateFromDir(): 33 migrations already installed, looking for more
2022/08/19 19:46:55 [INFO] database_migrate.go:91 migrateFromDir(): none found
2022/08/19 19:46:55 [WARNING] smtp_configure.go:15 smtpConfigure(): smtp not configured, no emails will be sent
2022/08/19 19:46:55 [INFO] smtp_templates.go:43 smtpTemplatesLoad(): loading templates: [confirm-hex reset-hex domain-export domain-export-error]
2022/08/19 19:46:55 [INFO] sigint.go:22 sigintCleanupSetup(): setting up SIGINT cleanup
2022/08/19 19:46:55 [INFO] router.go:52 routesServe(): starting server on 0.0.0.0:8080
2022/08/19 19:46:56 [INFO] version.go:54 func1(): New update available! Latest version: v1.8.7
2022/08/19 19:48:04 [INFO] version.go:12 versionPrint(): starting Commento
2022/08/19 19:48:04 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://postgres:redacted@db:5432/commento?sslmode=disable
2022/08/19 19:48:05 [INFO] database_migrate.go:47 migrateFromDir(): 33 migrations already installed, looking for more
2022/08/19 19:48:05 [INFO] database_migrate.go:91 migrateFromDir(): none found
2022/08/19 19:48:05 [WARNING] smtp_configure.go:15 smtpConfigure(): smtp not configured, no emails will be sent
2022/08/19 19:48:05 [INFO] smtp_templates.go:43 smtpTemplatesLoad(): loading templates: [confirm-hex reset-hex domain-export domain-export-error]
2022/08/19 19:48:05 [INFO] sigint.go:22 sigintCleanupSetup(): setting up SIGINT cleanup
2022/08/19 19:48:05 [INFO] router.go:52 routesServe(): starting server on 0.0.0.0:8080

When I perform a request to 0.0.0.0:8080 from the Pi, I get this response:

curl 0.0.0.0:8080 -l -k -i

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: http://commento.example.com:8080/login
Date: Fri, 19 Aug 2022 19:49:50 GMT
Content-Length: 73

<a href="http://commento.example.com:8080/login">Moved Permanently</a>.

I just don't get it, because connecting to that (even after changing it to my own domain and other domains (see below)) don't work, I just get an no response from the server. No logs. If I follow the official docs, things should work. But they don't.

So, let me sketch my scenario further.

I am running this on a Pi. I have a reverse proxy (caddy). It reverse proxies the traffic from commento.stenbrinke.nl to 127.0.0.1:8080, which is COMMENTO_ORIGIN in my case.

What should my COMMENTO_ORIGIN and my reverse_proxy URL be?

I tried http://localhost:8080, http://127.0.0.1:8080, `https://commento.stenbrinke.nl. None work.

i tried doing a request on my PC to my PI (192.168.2.2:8080) and all of those other urls. No response! but i have many other services running on ports on my pi, and doing a request to 192.168.2.2:8096 reaches that service, for example.

i am completley stuck, I do not understand why this doesn't work :)

I'd appreciate the help!

souramoo commented 2 years ago

Hey! So as you've realised, commento++ is indeed running and the port forwards are working - the redirect is produced by the commento server at https://github.com/souramoo/commentoplusplus/blob/master/api/router_static.go#L135

You basically just need to change the COMMENTO_ORIGIN to one that is accessible from the browsers you are intending to access the comments page (so they can contact the server hosting the dynamic functionality).

0.0.0.0 is simply a bind-all address which means the server will accept traffic from all network cards on your Pi, which means if you have two network cards and therefore two IPs, the server will still be able to accept traffic from all of them (rather than 127.0.0.1 which would only allow connections from localhost, or 192.168.2.2 which would only allow incoming connections from that network).

It is possible you have a firewall or similar that is blocking incoming traffic unless it is from certain ports, e.g. 80 after which it is reverse proxied?

I would recommend you set it to commento.stenbrinke.nl. This needs to be done in the docker-compose.yml file you had earlier. The commento.example.com comes from the documentation in the readme and the website.lol one comes from the tutorial you linked, so I fear you might be getting your different configurations mixed up - what is your current docker-compose file?

souramoo commented 2 years ago

(Oh, and make sure you don't include the :8080 in the origin address - this is because it appears your particular setup this port is inaccessible unless through your reverse proxy!)

sander1095 commented 2 years ago

I have got it to work now!

My caddyfile looks like this:

https://commento.MYDOMAIN.COM { # Change this to your own domain
        reverse_proxy localhost:8080
        encode gzip
}

My docker-compose.yml looks like this:

version: '3'

services:
  server:
    build: .
    ports:
      - 8080:8080
    environment:
      COMMENTO_ORIGIN: https://commento.MYDOMAIN.COM #Change this to your own domain. Must be the same as in caddyfile
      COMMENTO_PORT: 8080
      COMMENTO_POSTGRES: postgres://postgres:postgres@db:5432/commento?sslmode=disable
    depends_on:
      - db
    networks:
      - db_network
  db:
    image: postgres
    environment:
      POSTGRES_DB: commento
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    networks:
      - db_network
    volumes:
      - postgres_data_volume:/var/lib/postgresql/data

networks:
  db_network:

volumes:
  postgres_data_volume:

I can now go to https://commento.MYDOMAIN.COM (which has a TLS cert thanks to Caddy's easy let's encrypt integration) or to 192.168.2.2:8080/raspberrypi:8080 and I will be redirected to https://commento.MYDOMAIN.COM.

Not fully what I expected; I was expecting that I could also fully run this thing on localhost on the pi, without any reference to the live url (like any other service that I run on my pi like jellyfin), but this also works fine for me.

I guess this means that #119 can also be fixed by enabling arm architectures again, since building things locally seem to work fine on my pi! 🎉 I will go ahead and comment it there as well.