Search code examples
node.jsdeploymentstrapikoa

deploying strapi to VPS got 404 error from /i18n/locales when trying to log in


  • Front-end: gatsbyJS
  • Back-end: strapi, mysql, nginx
  • Strapi Version: 4.2.3
  • Operating System: Ubuntu v20.04.4 LTS or v18 or v22
  • Database: mysql v8.0.30
  • Node Version: v14.20.0 or v16
  • NPM Version: 6.14.17
  • Yarn Version: 1.22.19

I’m trying to deploy my project to VPS. It works fine when I develop the project locally on my computer. npm run start worked fine as well as npm run develop. It worked when I deployed it to EC2(t2.small) as well. But, after deployed it to VPS(provided from a small hosting company in my country), I got the 404 error when trying to log in on the admin page.

I cloned my project from my github and I got to the admin page(http://example.com/admin or http://exampleIP/admin). And then, I tried to log in but got the error so couldn’t get to the admin panel. Other responses are fine as you can see the picture below.

the screenshot of the error message

I got the same error when I tried it from the top with npx create-strapi-app. I also tried with the DB that I duplicated from my local PC to VPC but the result wasn't different. After I deployed it to AWS EC2 the error was gone finally for some reason.

Is there anyone who got the same issue or know something about this?

Just so you know, this is the nginx configuration on my VPS instance.

server{

  listen 80;
  listen [::]:80;
  server_name example.com;
  root /srv/my-project/frontend/public;
  index index.html index.htm index.nginx-debian.html;

  location / {
    try_files $uri $uri/ =404;
  }

  location /admin {
    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 X-NginX-Proxy true;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_cache_bypass $http_upgrade;
    proxy_pass http://localhost:1337/admin;
  }
}

Solution

  • use this conf

    location /i18n/locales {
        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 X-NginX-Proxy true;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_cache_bypass $http_upgrade;
        proxy_pass http://localhost:1337/i18n/locales;
    }