Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1498

Gofiber backend returns HTTP 502 when trying to connect to SSL port

$
0
0

I am developing a web application that utilizes nginx as reverse proxy + static files server and backend on go/gofiber. Recently I've bought a domain and ssl certificate to perform https connections, but when my frontend tries to access backend it return HTTP 502 error, while backend responds with connection refused. Here is the code:

nginx config:

server {    listen       80;    listen  [::]:80;    listen      443 ssl http2;    server_name    _._ www._._;    ssl_certificate /usr/share/nginx/certificate.crt;    ssl_certificate_key /usr/share/nginx/certificate.key;    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;    ssl_ciphers         HIGH:!aNULL:!MD5;    location / {        root   /usr/share/nginx/html;        index  index.html index.htm;    }    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   /usr/share/nginx/html;    }    location /notes {        proxy_pass http://172.20.128.1:2000;        proxy_set_header Host $host;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header   X-Forwarded-For $remote_addr;    }}

main.go:

package mainimport ("github.com/gofiber/fiber/v2""github.com/gofiber/fiber/v2/middleware/cors""github.com/gofiber/fiber/v2/middleware/logger""politex/backend/config""politex/backend/routers")func main() {    app := fiber.New()    config.Connect()    app.Use(cors.New())    app.Use(logger.New())    // Register routes for CRUD operations    routers.Register(app)    app.Listen(":3000")    app.ListenTLS(":443", "./ssl/certificate.crt", "./ssl/certificate.key")}

docker-compose.yml:

services:  backend:    build:      context: backend      dockerfile: Dockerfile    ports:      - "3000:3000"      - "2000:443"    networks:      static:        ipv4_address:          172.20.128.1    depends_on:      - db  db:    restart: always    image: postgres:16.4    ports:      - "5432:5432"    environment:      POSTGRES_USER: _      POSTGRES_PASSWORD: _      POSTGRES_DB: _    networks:        static:          ipv4_address:            172.20.128.2    volumes:      - pgdata:/var/lib/postgresql/data  bot:    image: sanyokk/polytex-telegram:v1  nginx:    image: sanyokk/frontend-nginx:v1    ports:      - "80:80"      - "443:443"    networks:        - staticvolumes:  pgdata:networks:  static:    ipam:      config:        - subnet: "172.20.0.0/16"

I've binded backend's 443 to 2000 as 443 is already in use by nginx


Viewing all articles
Browse latest Browse all 1498

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>