System Information
- **Strapi Version4.12.7:
- **Operating SystemUbuntu 22.04:
- **DatabaseMySQL:
- **Node Version18.17.1:
- NPM Version:
- Yarn Version:
Hi guys,
Tech-stuff:
Server: Ubuntu 22.04
Node: 18.17.1
Strapi: 4.12.7
I am hosting my Strapi application on an Ubuntu 22.04 server and I’ve ran into a routing problem with my production environment. I don’t know is the issue Strapi, Nginx, my imported database or something else. I run the production environment with PM2 and right now I can login to my Admin panel, but I cannot get my content vibes visible at all.
On production I have a few times done the classic command “rm -rf node_modules package-lock.json .cache build” and started Strapi from the ground up. Installing the app and building the application with NODE_ENV=production.
Here are the details from my PM2 log which confirm the application is up and running:
2|api-prod | [2023-08-31 20:24:48.786] http: GET /admin (32 ms) 200
2|api-prod | [2023-08-31 20:24:49.205] http: GET /admin/main.952ab803.js (10 ms) 200
2|api-prod | [2023-08-31 20:24:50.371] http: GET /admin/project-type (3 ms) 200 2|api-prod | [2023-08-31 20:24:50.812] http: GET /admin/init (19 ms) 200
2|api-prod | [2023-08-31 20:24:51.085] http: GET /admin/telemetry-properties (4 ms) 401
2|api-prod | [2023-08-31 20:25:05.989] http: POST /admin/login (275 ms) 200
2|api-prod | [2023-08-31 20:25:06.303] http: GET /admin/information (105 ms) 200 2|api-prod | [2023-08-31 20:25:06.486] http: GET /admin/users/me (148 ms) 200 2|api-prod | [2023-08-31 20:25:06.513] http: GET /admin/users/me/permissions (182 ms) 200 2|api-prod | [2023-08-31 20:25:06.889] http: GET /i18n/locales (78 ms) 200 2|api-prod | [2023-08-31 20:25:16.160] http: GET /admin/5317.0ea6043c.chunk.js (2 ms) 200
2|api-prod | [2023-08-31 20:25:18.841] http: GET /admin/content-type-builder.59029b56.chunk.js (2 ms) 200 2|api-prod | [2023-08-31 20:25:20.230] http: GET /admin/upload.883ac500.chunk.js (2 ms) 200
The interesting part here is the 401 error on admin/telemetry-properties and some other 404 errors. Few of them are objects so I’m sharing them below. Here are the Network errors from my Browser Tab that confirm 404 errors:
Main.js
{
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": "xhr",
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjkzNjcyNjQ4LCJleHAiOjE2OTYyNjQ2NDh9.joJOT72mbNnq2LovpIX8hEExH4SSddSd8ycyTxFCU7Q"
},
"paramsSerializer": {},
"baseURL": "https://varangianventure.com",
"signal": {},
"method": "get",
"url": "/content-manager/content-types"
}
Content-type-builder.chunk.js error:
{
"err": {
"message": "Request failed with status code 404",
"name": "AxiosError",
"stack": "AxiosError: Request failed with status code 404\n at ot (https://varangianventure.com/admin/main.952ab803.js:2856:1144)\n at XMLHttpRequest.Xt (https://varangianventure.com/admin/main.952ab803.js:2856:4556)",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": "xhr",
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjkzNjcyNjQ4LCJleHAiOjE2OTYyNjQ2NDh9.joJOT72mbNnq2LovpIX8hEExH4SSddSd8ycyTxFCU7Q"
},
"paramsSerializer": {},
"baseURL": "https://varangianventure.com",
"signal": {},
"method": "get",
"url": "/content-type-builder/reserved-names"
},
"code": "ERR_BAD_REQUEST",
"status": 404
}
}
Now I have done some curl commands on my terminal.
curl https://varangianventure.com/content-manager/content-types
This is the result I get:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
$ curl https://varangianventure.com/content-manager/init
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
curl http://127.0.0.1:1337/content-manager/init
Data below is obviously modified:
{"data":null,"error":{"status":404,"name":"NotFoundError","message":"Not Found","details":{}}}username@sportnumber:~$
Incase this has something to do with my Nginx configuration then here are the relevant parts of my config.
location ~ ^/(api|admin) {
proxy_pass http://127.0.0.1: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;
}
location /i18n/locales {
proxy_pass http://127.0.0.1:1337/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;
}
I actually had the /admin/ screen go blank until I added the /i18n/locales router to my Nginx config.
So let’s recap:
I have multiple times done “rm -rf nodule_modules package-lock.json build .cache” and done a new install of Strapi and build the environment with production environment.
PM2 is running the app. Logs indicate 200 + 404 GET-requests. Browser’s tab shows missing 404s.
Problem seems to be on the router. Is this something I must fix on the nginx proxying or does anyone have any alternative suggestions for me to attempt, next?