Connection refused on https port for Nginx container on AWS ec2 server

Viewed 20

I have a simple EC2 instance and a dockerized Laravel project is running on it. when I use a simple URL with HTTP it works and shows the website to me. Now I want to enable HTTPS on this website. I opened 443 port on Nginx but I get a connection refused for it. The HTTPS port on the server is open. this is my Nginx configuration:

nginx.conf:

server {
    listen 80;
    listen [::]:80;
    index index.php index.html;
    server_name _;
    root /var/www/html/public;

    location / {
       return 301 https://$host$request_uri;
    }
}
server {
    listen 443 default_server ssl http2;
    listen [::]:443 ssl http2;
    root /var/www/html/public;
    server_name _;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass backend:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

docker-compose.yml

version: '3'

services:
    nginx:
        build:
            context: docker/nginx
            dockerfile: Dockerfile
            args:
                - NGINXUSER=${NGINXUSER:-www-data}
                - NGINXGROUP=${NGINXGROUP:-www-data}
        container_name: nginx
        ports:
            - '${APP_PORT:-80}:80'
            - '443:443'
        volumes:
            - .:/var/www/html:delegated
        restart: unless-stopped
        depends_on:
            - backend
            - redis
        networks:
            - reminder_network

but when I enter URL with https i get this error:

curl: (7) Failed to connect to ***.amazonaws.com port 443 after 9 ms: Connection refused

0 Answers
Related