Score:0

Hosting 2 apps on different ports using nginx proxy_pass

in flag

Why does the proxy_pass http://backends/; under the location /textcat bring me to the root of the server (localhost:8081) and proxy_pass http://backends; (no trailing /) brings me to (seemingly) localhost:8081/textcat.

I am trying to host two applications running locally on the server. These two applications are running on port 8081 and 8082. I would like to access the app at 8081 via the /textcat location and 8082 via /ner. I was able to do this with the configuration below. But I dont quite understand why this works?

upstream backends {
    server localhost:8081; # change to the port the webapp is listening on.
}


upstream backends_NER {
    server localhost:8082; # change to the port the webapp is listening on.
}

server {
    listen 443 ssl;
    server_name "";
    ...SSL Stuff...

    location = /textcat {
        proxy_pass http://backends/;

  }
    location /ner {
        proxy_pass http://backends_NER/;# This seems to work because of the trailing slash. Since the http_referrer is /ner our proxy path has to have the trailing /
  }
# have to redirect on a any location request, and if the referrer is /textcat do localhost:8081
    location / {
    if ($http_referer ~* (/textcat) ) {
        proxy_pass http://localhost:8081;
    }
    if ($http_referer ~* (/ner) ) {
        proxy_pass http://localhost:8082;
    }
  }
}
jp flag
This behavior is described in the documentation for ` proxy_pass`.
us flag
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.