Impossible to get Strapi working on Ubuntu/Nginx subdomain

System Information
  • Strapi Version: 3.6.5
  • Operating System: Ubuntu 20.04
  • Database: Mongo DB
  • Node Version: 14.17.1
  • NPM Version: 6.14.13
  • Yarn Version: 1.22.10

I’ve been stuck for days trying to solve my Strapi deployment.
I have a VPS (2vCores, 2GB ram) on Ubuntu 20.04 up-to date with Nginx and SSL

I am working on a project with Nuxt pointing to mydomain[dot]com (up and running with pm2), and I want to deploy strapi on strapi.mydomain.com.

I used the upstream.conf in etc>nginx>conf.d:

# Strapi server
upstream strapi {
    server 127.0.0.1:1337;
}

Here’s my Nginx config file in etc>nginx>sites-available>strapi[dot]mydomain[dot]com:

server {
        root /var/www/strapi.mydomain.com/html;

        server_name strapi.mydomain.com;

        location / {
                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 "Upgrade";
                proxy_pass_request_headers on;
                try_files $uri $uri/ =404;
        }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = strapi.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name strapi.mydomain.com;

        # Proxy Config
            location / {
                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 "Upgrade";
                proxy_pass_request_headers on;
            }
    return 404; # managed by Certbot
}

When using “yarn develop”, I get the welcome panel with the button “Create the first administrator”, but as a note: images are not loading.

Clicking the button returns a 404 page on strapi[dot]mydomain[dot]com/admin
Capture d’écran 2021-06-28 à 11.21.59

Tried yarn build, then yarn start: always the same

All tutorials / docs / videos / whatever available have no effect. Followed this one here: Is there documentation on how to deploy and setup strapi with a VPS with Ubuntu 20.04? as well with the same outcome. There is something wrong that I’m out of options to try. Can anyone help?
Thank you so much!

I would suggest trying our Nginx Config instead: Nginx Proxying - Strapi Developer Documentation

Also is your Strapi instance being ran with PM2?

I just finished reconstructing the server and started from scratch the whole procedure and thanks to your Nginx config. This is now working! Both with yarn develop (while constructing the api) and pm2!

Awesome! Glad to hear that :slight_smile: