5 ms·
This nginx local dev config snippet is one-and-done: # Proxy to a backend server based on the hostname. if (-d vhosts/$host) { proxy_pass http://unix:v
by sigil 1y ago
This nginx local dev config snippet is one-and-done:
# Proxy to a backend server based on the hostname.
if (-d vhosts/$host) {
proxy_pass http://unix:vhosts/$host/server.sock;
break;
}
Your local dev servers must listen on a unix domain socket, and you must drop a symlink to them at eg /var/lib/nginx/vhosts/inclouds.localhost/server.sock.
Not a single command, and you still have to add hostname resolution. But you don't have to programmatically edit config files or restart the proxy to stand up a new dev server!
- ku1ik 1y agoThis is neat!
- hn92726819 1y agoI'm not that familiar with nginx config. Does this protect against path traversal? Ex: host=../../../docker.sock
- sigil 1y agonginx validates hostnames per the spec, and to your question specifically it rejects requests that would put a slash in $host: https://github.com/nginx/nginx/blob/b6e7eb0f5792d7a52d2675ee3906e502d63c48e3/src/http/ngx_http_request.c#L2221 https://github.com/nginx/nginx/blob/b6e7eb0f5792d7a52d2675ee...