Score:0

same proxy pass config not working on both instances

gp flag

i have a config /etc/nginx/sites-available/test that only proxies one server the first (blog) and returns a nginx 404 on the second (api) I have tried trouble shooting but to no avail

i tried checking for any syntax or spelling errors i copied the working directive and only replace the server path and name i deleted one directive and it works flawless but not when both are there

upstream blog {
    server 127.0.0.1:3001;
}

upstream api {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    listen [::]:80;
    
    server_name local.net www.local.net;
    
    location /blog/ {
        rewrite ^/blog(.*)$ $1 break;
        proxy_pass http://blog/;
        include proxy_params;
    }
}

server {
    listen 80;
    listen [::]:80;
    
    server_name api.local.net;
    
    location /api/ {
        rewrite ^/api(.*)$ $1 break;
        proxy_pass http://api/;
        include proxy_params;
    }
}
in flag
The 404 could be returned by the API server, not nginx.
Jaromanda X avatar
ru flag
what *trouble shooting* have you tried, just so we don't waste our time and yours offering the same troubleshooting steps you've already tried
georgy avatar
gp flag
Hi @JaromandaX Thanks for the reply... I tried interchanging the proxy routes i.e taking blog to where api is which results in api working and blog returns 404
georgy avatar
gp flag
Hello @GeraldSchneider Thanks for replying... No the error is the default nginx error... However if i change the api block to the blog one it works but then blog returns 404
Jaromanda X avatar
ru flag
so what you're saying is that `127.0.0.1:3000;` is the issue
georgy avatar
gp flag
Hi @JaromandaX not exactly, the port is not the problem because as I pointed out earlier if i move the server on port 3000 to be the first nginx server block it would work but now the 3001 would return a 404 and vice versa
Jaromanda X avatar
ru flag
I misunderstood what you meant by interchanging proxy routes, I thought the issue is that not matter which port / "path", it's the API service that returns 404
georgy avatar
gp flag
@JaromandaX no problem am new to this and had no idea how to place and explain my issue
Jaromanda X avatar
ru flag
so, it's not the uopstream api at server 127.0.0.1:3000; that is always returning 404, it's whatever `server` is configured later in the config?
georgy avatar
gp flag
@JaromandaX its not the api server since that would return a json 404 and the one am facing is the default nginx 404 despite which server i put in the second block if i move the api block up it works but then my blog returns nginx 404
georgy avatar
gp flag
i ended up going with reverse proxying via individual configs under `/etc/conf.d/*` i.e `/etc/nginx/conf.d/example.com.conf` ```server { listen 80; server_name example.com; location / { proxy_pass http://destination; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }```
Score:0
gp flag

i ended up going with reverse proxying via individual configs under /etc/conf.d/* i.e

/etc/nginx/conf.d/example.com.conf

server {
  listen 80;
  server_name example.com;

  location / {
    proxy_pass http://destination;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}
I sit in a Tesla and translated this thread with Ai:

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.