I created a website which uses a nuxtjs frontend and a strapi backend. After deployment to a VPS, I cannot get the strapi routing to work. I read multiple posts about this on the internet and followed the official documentation about nginx proxying but to no evail.
Path: /etc/nginx/sites-available/example.com
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1: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;
}
# Strapi API and Admin
location /strapi/ {
rewrite ^/strapi/(.*)$ /$1 break;
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;
}
}
Path: backend/config/server.js
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: 'http://example.com/strapi',
});
Visiting example.com reveals the frontend, as intended. Visiting example.com/strapi reveals the following site:
Clicking on the 'Open admnistration' button leads me to example.com/admin, which returns my 404 frontend error page.
I would be very thankful for any kind of help.