this post was submitted on 01 Nov 2023
1 points (100.0% liked)
Side Project
29 readers
1 users here now
A community for sharing and receiving constructive feedback on side projects.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
My stack is:
Separate backend Nodejs project served with REST at api.domain.com
Separate Frontend Nextjs project built with Static Site Generation
And Nginx as reverse proxy
In that situation, we can configure Nginx to route requests accordingly. We can set it up to forward requests with a path starting with "/api" to our Node.js application, and route all other requests to our Next.js application.
server {
listen 80;
# Redirect /api requests to Node.js
location /api {
proxy_pass http://127.0.0.1:3001; # Assuming your Node.js app is running on port 3001
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;
}
location / {
proxy_pass http://127.0.0.1:3000; # Assuming your Next.js app is running on port 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;
}
}