title: Cannot access Strapi in a container using AWS Lightsail, Ubuntu, Docker and NGINX
body: <p>I'm trying to practice and I have created an instance using AWS Lightsail with Ubuntu 20.04 LTS, also I've installed Docker and Docker Compose.</p>
  <p>I would like to run this applications:</p>
  <ol>
  <li>MariaDB</li>
  <li>Strapi CMS</li>
  </ol>
  <p><em>Let's assume that my public IP is: 1.20.20.20</em></p>
  <p>When I try to access &quot;http://1.20.20.20:1337&quot;, I receives &quot;This site can’t be reached&quot;.</p>
  <p>I thought that maybe I needed a web server and I have included NGINX in my docker-compose configuration.</p>
  <p><strong>My folders in the instance:</strong></p>
  <ul>
  <li>envs/strapi.env</li>
  <li>nginx/strapi.conf</li>
  <li>docker-compose.yml</li>
  </ul>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: '3.8'
  
  services:
          nginx:
                  image: nginx:stable
                  container_name: nginx
                  volumes:
                          - ./nginx/strapi.conf:/etc/nginx/conf.d/default.conf
                  ports:
                          - 80:80
                  restart: on-failure
                  depends_on:
                          - strapi
  
          db:
                  image: mariadb:10.6.4
                  container_name: db
                  restart: always
                  env_file:
                          - envs/db.env
                  volumes:
                          - db-data:/var/lib/mysql
                  networks:
                          - apps
  
          strapi:
                  image: strapi/strapi:3.6.8
                  container_name: strapi
                  env_file:
                          - envs/strapi.env
                  restart: always
                  depends_on:
                          - db
                  ports:
                          - 1337:1337
                  networks:
                          - apps
  
  volumes:
          db-data:
  
  networks:
          apps:
                  driver: bridge
  </code></pre>
  <p><strong>nginx/strapi.conf</strong> (I have copied the configuration from <a href="https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/deployment/optional-software/nginx-proxy.html#nginx-virtual-host" rel="nofollow noreferrer">Strapi docs</a>):</p>
  <pre><code>server {
      # Listen HTTP
      listen 1337;
      server_name 1.20.20.20;
  
      # Static Root
      location / {
          root /var/www/html;
      }
  
      # Strapi API
      location /api/ {
          rewrite ^/api/?(.*)$ /$1 break;
          proxy_pass http://strapi;
          proxy_http_version 1.1;
          proxy_set_header X-Forwarded-Host $host;
          proxy_set_header X-Forwarded-Server $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Host $http_host;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection &quot;Upgrade&quot;;
          proxy_pass_request_headers on;
      }
  
      # Strapi Admin
      location /admin {
          proxy_pass http://strapi/admin;
          proxy_http_version 1.1;
          proxy_set_header X-Forwarded-Host $host;
          proxy_set_header X-Forwarded-Server $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Host $http_host;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection &quot;Upgrade&quot;;
          proxy_pass_request_headers on;
      }
  }
  </code></pre>
  <p>Still cannot access the CMS using my browser.</p>
  <p>For some reason, when I do &quot;docker ps -a&quot;, the status of the nginx container is always Restarting....</p>
  <p>I have tried to follow and read steps that I have found on a few articles without luck. I don't have a lot of experience using NGINX and Ubuntu servers.</p>
  <p>My goal is to be able to access the web app (Strapi CMS) through my browser.</p>
  <p>Any help would be appreciated.</p>