Skip to content

Instantly share code, notes, and snippets.

@ehfeng
Created July 10, 2022 21:11
Show Gist options
  • Save ehfeng/f2c73e89fcd5d55119b37e928e82108f to your computer and use it in GitHub Desktop.
Save ehfeng/f2c73e89fcd5d55119b37e928e82108f to your computer and use it in GitHub Desktop.
Mapping requests to localhost servers based on Accept header
events {
worker_connections 1024;
}
http {
map $http_accept $accept {
default app;
~text/html web;
}
upstream app {
server localhost:8888;
}
upstream web {
server localhost:3000;
}
server {
listen 8080;
server_name localhost;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://$accept;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment