T
Twenty10mo ago
paulyili

Has anyone successfully got this working on docker and Nginx?

I can get this running on docker with localhost. but nothing i do will make it work when using nginx reverse proxy. in the console (chrome) i get "index-O3h98bLs.js:132 POST https://192.168.1.195:3000/graphql net::ERR_SSL_PROTOCOL_ERROR" then "Uncaught (in promise) ApolloError: Failed to fetch" If i remove my SSL, i get a CORS error. Im all out of ideas but really keen on getting this running though the reverse proxy. I've tried different settings on the. env file, using IPs instead of localhost, pointed the database to the docker network or letting it configure itself. have tried a few things in nginx but everything i've tried still gives me the same error.
No description
30 Replies
charles
charles10mo ago
As your front is server on an https route, your browser will require the XHR calls to be done over https too (otherwise you will get this CORS error). This means your must serve your server over https. To serve your server in https, you'll need to configure your nginx to serve it over https. Here is an example configuration: https://gist.github.com/basharovV/e25989cc918f0b21ded26c8bf3be8400
Gist
How to configure HTTPS with Lets Encrypt, Nginx reverse proxy, Expr...
How to configure HTTPS with Lets Encrypt, Nginx reverse proxy, Express and Node - https_nginx_express_node_config.md
charles
charles10mo ago
You can look into "let's encrypt" to generate your own ssl certificate if you don't have one for your domain Alternatively you can also use a service such as cloudflare or cloudfront (aws) to handle the certificate for you but connect to your server in http behind the scene (this means it's not end-to-end encryption but this is generally acceptable)
paulyili
paulyiliOP10mo ago
Thsts odd. Because I am using let's encrypt with npm. I'm using nginx proxy manger (gui). Setting a ssl is quite easy (as I've done for other apps) If i remove the SSL I get the CORS error.
paulyili
paulyiliOP10mo ago
this is what i get in chrome.
No description
No description
charles
charles10mo ago
yep, your https is failing, it should be on your nginx config side, not sure where
paulyili
paulyiliOP10mo ago
Any recommendations? its a very standard config in nginx proxy manager. (works for every other docker container i have running) cache assets, block common exploits, WebSocket support. SSL is just Let's encrypt. Should i have a different url for each port? i.g twenty.myurl.com & twentyapi.myurl.com? does it need headers? Im not to technical with NPM unfortunately.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
So for example .env file, the front end should point to localhost or the vm IP. And the backed should point to twenty-api.myurl.com ? like this: TAG=latest PG_DATABASE_URL=postgres://twenty:twenty@twenty-db:5432/default FRONT_BASE_URL=http://192.168.1.123:3001 LOCAL_SERVER_URL=http://twenty-api.myurl.com ACCESS_TOKEN_SECRET=PASSWORD2 LOGIN_TOKEN_SECRET=PASSWORD3 REFRESH_TOKEN_SECRET=PASSWORD4 SIGN_IN_PREFILLED=false POSTGRES_USER=postgres POSTGRES_PASSWORD=PASSWORD1 POSTGRES_ADMIN_PASSWORD=PASSWORD1
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
yeah, so i have for example twenty.mydomain.com > 192.168.1.123:3001 twenty-api.mydomain.com > 192.168.1.123:3000 both with websocket support & lets encrypt SSL.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
Oh wow. this is a little beyond my knowledge. little overwhelming so to speeak. i understand what you've done, are you willing to walk though this with me?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Stix
Stix10mo ago
Hello, I have the same problem could you please share your docker .env?
paulyili
paulyiliOP10mo ago
Actually, do you mind sharing an .env file? I have all the containers running , but having trouble understanding the nginx configuration to get it talking to my nginx proxy manager. The nginx configuration you have is set to port 80, Do change this to the port I have my url is set to, in nginx proxy manager (gui) e.g crm.mydomain.com > 192.168.1.123:3300 ? In the compose file, you have a variable for "port" which port is that for if using the default 3000 and 3001? Or is this the url port?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
hmm, pretty much the same as my conf.
I've basically used your dockercompose. your .conf (filled out) and the twenty.conf which is in it's nginx folder. all in the twenty folder. all containers are running with no errors if i run that as is, with filled UUID & domain names. i have left port 80 on the docker-compose file and nginx. i've set my nginx proxy manager for my twenty.myurl.com to be on port 80 with the VM ip 192.168.1.123 for example. i get 502 error when i go to the url. that's where im stuck.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
i think that's from nginx proxy manager. because if i try to ping 192.168.1.123:80 from my windows pc in powershell it fails. i also just saw this in my browser console crm.myurl.com/:1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received okay i managed to get it to work, i had to set the nginx ports to 3300:3300
version: "3.9"
services:
nginx:
image: nginx
ports:
- "3300:3300"
volumes:
- ./nginx/twenty.conf:/etc/nginx/conf.d/twenty.conf:ro
version: "3.9"
services:
nginx:
image: nginx
ports:
- "3300:3300"
volumes:
- ./nginx/twenty.conf:/etc/nginx/conf.d/twenty.conf:ro
weirdly, the first time i tried this, it gave me the same HTTPS error. now it actually worked. i must have changed something else. what would the "server" url be if they're all being redirected to the same 3300 port for me as usually it's 3000 and 3001 ?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
To get API to work i had to change the docker compose & twenty.conf
version: "3.9"
services:
nginx:
image: nginx
ports:
- "3300:3300" #crm.mydomain.com
- "3301:3301" #crm-api.mydomain.com
volumes:
- ./nginx/twenty.conf:/etc/nginx/conf.d/twenty.conf:ro
environment:
- VIRTUAL_HOST=crm.mydomain.com
- VIRTUAL_PORT=3300
- VIRTUAL_PROTO=http
networks:
- twenty_frontend
- twenty_backend
- nginx_proxied
version: "3.9"
services:
nginx:
image: nginx
ports:
- "3300:3300" #crm.mydomain.com
- "3301:3301" #crm-api.mydomain.com
volumes:
- ./nginx/twenty.conf:/etc/nginx/conf.d/twenty.conf:ro
environment:
- VIRTUAL_HOST=crm.mydomain.com
- VIRTUAL_PORT=3300
- VIRTUAL_PROTO=http
networks:
- twenty_frontend
- twenty_backend
- nginx_proxied
# New server block for crm-api.mydomain.com
server {
listen 3301; # New listening port for the API

server_name crm-api.mydomain.com; # New domain for the API

# Route all requests to the backend
location / {
proxy_pass http://backend; # Forward all requests to the backend
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
# New server block for crm-api.mydomain.com
server {
listen 3301; # New listening port for the API

server_name crm-api.mydomain.com; # New domain for the API

# Route all requests to the backend
location / {
proxy_pass http://backend; # Forward all requests to the backend
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
this allowd me to use crm-api.mydomain.com for the API which worked.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
What does the console tab show when you try load the page
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
hmm. if it's not throwing errors. like a HTTPS one and apolloerror. id try this. sudo docker exec -it {your_backend_container} /bin/sh yarn:databasereset then exit exit
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
paulyili
paulyiliOP10mo ago
I did that originally 🙂 but was /api but their playground wasn't accepting it for some odd reason. so i couldn't see any API endpoints i could use.
charles
charles10mo ago
@paulyili did you manage to get it working?
paulyili
paulyiliOP10mo ago
Yep, got it running properly
charles
charles10mo ago
wonderful!
Want results from more Discord servers?
Add your server