Skip to content

Instantly share code, notes, and snippets.

@shiroze
Last active December 1, 2024 07:19
Show Gist options
  • Select an option

  • Save shiroze/bc2569e6d9080e138f4d4c657f341707 to your computer and use it in GitHub Desktop.

Select an option

Save shiroze/bc2569e6d9080e138f4d4c657f341707 to your computer and use it in GitHub Desktop.
Nginx
http {
...
server {
listen 80;
server_name example.com;
# Proxy requests to Program A (port 3000)
location /PAA {
root "C:/D/AppHost/web/build/";
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;
}
# Proxy requests to Program B (port 4000)
location /PAB {
root "C:/D/AppHost/web/build/";
proxy_pass http://localhost:4000;
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;
}
# DEFAULT
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;
}
location /api {
proxy_pass http://localhost:3000/api;
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 /_next/static {
alias /path/to/nextjs-app/.next/static;
}
location /_next/image {
proxy_pass http://localhost:3000/_next/image;
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;
}
# CORS configuration
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, Accept';
add_header 'Access-Control-Expose-Headers' 'Content-Type, Authorization, Accept';
add_header 'Access-Control-Allow-Credentials' 'true';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment