Configure NGINX, Docker Compose, AWS EC2

Viewed 14

I have an EC2 AWS instance and I want to create a test environment for an application. All other containers are working properly, but NGINX's is the only one that is not stable and keeps restarting constantly.

I tried in several ways to make NGINX run. Change addresses I used Return 301. Tried to remove certbot, nothing worked.

I'm an intern and I need to create this test environment for an assessment. Can someone help me?

my docker-compose.yml is like this

version: "3.9"

services:
  backend:
    container_name: backend
    image: <my_image>
    restart: always
    ports:
      - "3030:3030"
    environment:
      - "DATABASE_URL=${DATABASE_URL}"
      - "SERVER_PORT=${SERVER_PORT}"
      - "JWT_SECRET=${JWT_SECRET}"
  sniffer:
    container_name: mqtt-sniffer
    image: <my_image>
    restart: always
    environment:
      - "POSTGRES_DB=${POSTGRES_DB}"
      - "POSTGRES_USER=${POSTGRES_USER}"
      - "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}"
      - "POSTGRES_HOST=${POSTGRES_HOST}"
      - "MQTT_CLIENT_ID=${MQTT_CLIENT_ID}"
      - "MQTT_USER=${MQTT_USER}"
      - "MQTT_PASSWORD=${MQTT_PASSWORD}"
      - "MQTT_HOST=${MQTT_HOST}"
      - "MQTT_PORT=${MQTT_PORT}"
  web:
    container_name: web
    image: <my_image>
    restart: always
  nginx:
    container_name: nginx
    image: nginx:latest
    restart: always
    ports:
      - "80:80"
      - "443:443"
    environment:
      - API_SERVER_NAME=${API_SERVER_NAME}
    volumes:
      - /home/ubuntu/app/nginx/default.conf:/etc/nginx/nginx.conf:ro
      - /home/ubuntu/app/certbot/www:/etc/nginx/acme_challenge:ro
      - /home/ubuntu/app/certbot/certificate:/etc/nginx/certificate:ro

and my default.conf is like this

events {}

http {
    server {
        listen 80;
        listen [::]:80;

        server_name 18.231.90.250;

        location /.well-known/acme-challenge/ {
            root /etc/nginx/acme_challenge;
        }

        location / {
            proxy_pass http://18.231.90.250;
        }
    }

    server {
        listen 80;
        listen [::]:80;

        location /.well-known/acme-challenge/ {
            root /etc/nginx/acme_challenge;
        }

        location / {
            proxy_pass http://web:80;
        }
    }


    server {
        listen 443 default_server ssl;
        listen [::]:443 ssl;
    
        ssl_certificate /etc/nginx/certificate/live/teste.clientautoponia.com/fullchain.pem;
        ssl_certificate_key /etc/nginx/certificate/live/teste.clientautoponia.com/privkey.pem;

        location / {
            proxy_pass http://backend:3030;
        }
    }

I don't need to have the ssl certificate, I just want to be able to communicate when accessing the instance. Get a 200 when trying to access the address.

0 Answers
Related