I try to use NGINX inside a Docker Container with my Spring Boot App running both on localhost (later on a server).
NGINX should act as a reverse Proxy for the App running on port 5500. The App has a working Endpoint for GET localhost:5500/test
@RestController
public class TestController {
@GetMapping(value = "/test")
public String get(){
return "test";
}
}
With the use of NGINX i try to acces the Endpoint over localhost:8080/api/test, but i get always a 502 Bad Gateway.
NGINX config inside the Docker Container
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location / {
root /usr/share/nginx/html;
try_files $uri /index.html;
}
location /api {
proxy_pass http://127.0.0.1:5500/test;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
}
NGINX works fine a serves on / a default index.html
NGINX Error
[error] 31#31: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.22.0.1, server: , request: "GET /api/test HTTP/1.1", upstream: "http://127.0.0.1:5500/api/test", host: "127.0.0.1:8080"
"GET /api/test HTTP/1.1" 502 157 "-" "PostmanRuntime/7.28.1"