0

I have the following...

version: '2' services: main-nginx: image: nginx:latest container_name: nginx volumes: - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf - ./nginx/src:/usr/src ports: - "80:80" - "443:443" ui: container_name: ui image: cbusha-ui:latest be: container_name: be image: cbusha-be:latest ports: - "8080:8080" server { listen 80; listen 443 ssl; ssl_certificate /usr/src/site.crt; ssl_certificate_key /usr/src/site.key; server_name me.com; # include /usr/src/allow-cloudflare-only.conf location /services { rewrite /services/(.*) /$1 break; proxy_pass http://be:8080; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header HOST $host/work; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Frame-Options SAMEORIGIN; } location / { proxy_pass http://ui:3000/; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Frame-Options SAMEORIGIN; } } 

When I try to access the backend directly it works fine...

enter image description here

But when I try to use the NGINX proxy I get a 400

enter image description here

What am I missing?

Note the ui works fine so...

enter image description here

Also to be clear the names in the urls such as http://be:8080 is the container name in docker so those have been forwarded to localhost to prove it works but I can also run it directly on the container as is...

enter image description here

Update

So I changed it to

location /services { proxy_pass http://be:8080/; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } 

But I still get a 400 when I call

https://localhost/services/heartbeat

and a 200 when I call

http://localhost:8080/heartbeat

7
  • serverfault.com/a/586614/211028 Commented Sep 28, 2023 at 19:55
  • Also directive proxy_set_header HOST $host/work; is wrong because host name cannot contain slash. Commented Sep 28, 2023 at 19:58
  • proxy_set_header X-Frame-Options SAMEORIGIN; is useless. This header should be sent to browser, not to backend Commented Sep 28, 2023 at 19:59
  • tried changing per your request @AlexeyTen but no luck see update Commented Oct 1, 2023 at 2:55
  • Try proxy_pass http://be:8080/services Commented Oct 1, 2023 at 5:41

0

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.