7

I'm trying to configure nginx so I can have two locations. One for my node API and the other for my Jenkins CI.

http://my_ip/api should point to my node server and http://my_ip/jenkins should point to my jenkins CI

I have this server block.

server { listen 80; server_name my_ip_address; location /api { proxy_pass http://127.0.0.1:1234; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location /jenkins { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://localhost:8080; proxy_read_timeout 90; } } 

That config is not working. But if I use any of those locations matching to root it works.

This works with no problem. And the same if I use the location block of my node api with / only.

location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://localhost:8080; proxy_read_timeout 90; } 

But if I change / to /jenkins it doesn't work anymore.

I know I'm missing some basic pice of knowledge here, but I can't figure this out since everywhere I look seems to suggests that should be working ok.

1 Answer 1

12

Well, after some more research on the subject I've noticed that the problem with that setup was that the location /api was not connecting to http://127.0.0.1:1234/ it was trying to connect to http://127.0.0.1:1234/api and the same with jenkins.

So the solution is adding trailing slashes to both the location and proxy_pass.

location /api/ { proxy_pass http://127.0.0.1:1234/; .... location /jenkins/ { proxy_pass http://localhost:8080/; proxy_read_timeout 90; .... 

So that did the trick.

2
  • 2
    You just saved my day! Commented Aug 22, 2019 at 3:34
  • If I could give +100 on this.. I would do it .. great thanks Commented Aug 27, 2021 at 22:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.