404 Not Found from /i18n/locales when trying to log in

System Information
  • Strapi Version: 4.2.3
  • Operating System: Ubuntu 20.04.4 LTS
  • Database: mysql Ver 8.0.30 for Linux on x86_64 (MySQL Community Server - GPL)
  • Node Version: v14.20.0
  • NPM Version: 6.14.17
  • Yarn Version: none
  • Front-end: gatsbyJS
  • Back- end: strapi, mysql, nginx

I’m trying to deploy my project to VPS. It works fine when I develop the project locally on my computer. npm run start works fine as well as npm run develop.
But, after deployed it to VPS, I got the 404 error when trying to log in on the admin page.

I cloned the project from my github and

npm install
NODE_ENV=production npm run build
NODE_ENV=production npm run start

I got to the admin page(http://MYDOMAIN.com/admin or http://MYIP/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.

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 MYDOMAIN.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;
  }
}
2 Likes

I have the same issue. Have you managed to solve it?
Btw everything works just fine if you have location as root / , instead of /admin or anything else custom.

Setting up nginx server with location blocks that correspond to routes like: domain.com/strapi/api;
domain.com/strapi/admin haven’t worked for me.
But what worked perfectly fine is having multiple subdomains for each server block like this:
strapi.domain.com - server block for strapi (could be any subdomain) + proxy pass for strapi instance running on a system
domain.com - block for let’s say your frontend application e.t.c.
For example:

server {

    server_name strapi.yourdomain.com;

    location / {
            proxy_pass http://localhost:1337; 
            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;
    }

}

#and one more server block for front-end
server {

    server_name yourdomain.com www.yourdomain.com;

    location /  {
             proxy_pass http://localhost:3000; 
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection 'upgrade';
             proxy_set_header Host $host;
             proxy_cache_bypass $http_upgrade;
    }

}

1 Like

Im also facing this same issue. Does the above method fix this issue?

Hello, yes. If you’re okay with subdomains it’ll work just fine. My nginx + strapi setup on vps works with subdomains as I described above.

I haven’t logged in Strapi for a while.
I solved this problem by setting NGINX config.
I don’t recall the post I got a hint from, but adding ‘rewrite’ worked for me like below.
(MYDOMAIN.com for GatsbyJS, api.MYDOMAIN.com for Strapi)

/etc/nginx/conf.d/upstream.conf

upstream strapi {
    server 127.0.0.1:1337;
}

/etc/nginx/sites-available/strapi.conf

server {
  # force https
  listen 80;
  listen [::]:80;
  server_name www.MYDOMAIN.com;
  return 301 https://$host$request_uri;
}

server {
    listen 80;
    server_name api.MYDOMAIN.com;

   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 "Upgrade";
        proxy_pass_request_headers on;
    }

    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;
    }
}

I hope it would help someone like I got from someone here.

1 Like

Run npm run build before executing npm run develop. I noticed that the .strapi folder is essential for logging into the Strapi admin panel.