1

I have a some issue when trying to deploy a simple FastAPI application with Nginx on Google Cloud Platform. In my case I should use SSH-terminal to run Docker container with Nginx and FastAPI. My nginx.conf configuration looks like:

access_log                  /var/log/nginx/app.log;
error_log                   /var/log/nginx/app.log;

server {
  server_name               example.com;
  listen                    80;
  return 301 https://$host$request_uri;
}

server {
  listen                  443 ssl;
  server_name             example.com;
  ssl_certificate         /root/ssl/cert.pem;
  ssl_certificate_key     /root/ssl/key.pem;
  location / {
    proxy_pass "http://example.com:8004/";
  }
}

And my docker-compose.yml looks like:

version: '3.8'

services:
  nginx-proxy:
    image: nginx
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx:/etc/nginx/conf.d
      - ./ssl/cert1.pem:/root/ssl/cert.pem
      - ./ssl/privkey1.pem:/root/ssl/key.pem
      - ./ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem

  web:
    environment: [.env]
    build: ./project
    ports:
      - 8004:8000
    command: gunicorn main:app -k uvicorn.workers.UvicornWorker -w 2 -b 0.0.0.0:8000
    volumes:
      - ./project:/usr/src/app

networks:
  default:
    external:
      name: nginx-proxy

Also, I have a Google Cloud VM instance with Firewall HTTP, HTTPS traffic On option, and additionally configured Firewall with rules allowed TCP connections over 443 and 80 ports (Domain name is provided by Google Cloud also, and redirects to VM's external IP address when I put it in my browser address field).

I run my docker-image from SSH-terminal with docker-compose up --build, then I get 502 Bad Gateway Nginx error in my browser (after going to example.com). I would like to know whether it is possible to run the docker image this way from inside SSH-terminal, as well as which steps did I miss to do it the right way?

Chris
  • 18,724
  • 6
  • 46
  • 80
Egor Richman
  • 559
  • 3
  • 13

0 Answers0