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