I have an application that frequently polls the server. My ultimate goal is to conditionally proxy requests to one of two servers depending on the path of the request - anything going to /notifications
goes to localhost while everything else should go to a bigger server via proxy_pass
. Here is my best guess at how to do that:
server {
listen 443;
server_name localhost;
location / {
set_by_lua $proxyUrl '
if string.match(ngx.var.uri, "/notifications")
then
return "https://localohst:8080"
else
return "https://bigger-server.com"
end
';
proxy_pass $proxyUrl;
}
}
server {
listen 8080;
server_name localhost;
location / {
root /usr/local/openresty/nginx/html;
index index.html;
}
}
Before that, though, I can't even get this to work - it returns a 502:
server {
listen 80;
server_name localhost;
location / {
set_by_lua $proxyUrl '
return "https://bigger-server.com"
';
proxy_pass $proxyUrl;
}
}
This is a two-part question, I suppose. 1) Why doesn't my simple example work? 2) Am I on the right path with my larger goal?