How do I create a nginx configuration for a docker-compose setup with a spring boot API…
- User
How do I create a nginx configuration for a docker-compose setup with a spring boot API and a React app so that both can be accessed using a nginx reverse proxy?
- Assistant
Here is an example of an nginx configuration that can be used to reverse proxy both a Spring Boot API and a React app in a Docker Compose setup:
bashhttp { server { listen 80; server_name example.com; location /api { proxy_pass http://spring_boot_api:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { proxy_pass http://react_app:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }In this example, the API is listening on port
8080of thespring_boot_apiservice and the React app is listening on port3000of thereact_appservice. The nginx server is listening on port80and will forward all requests to/apito the Spring Boot API and all other requests to the React app.Note that you'll need to replace
example.comwith your own domain name and make sure that your Docker Compose file uses the correct service names. Additionally, you may need to make adjustments to theproxy_passandproxy_set_headerdirectives based on your specific setup. - User
My domain is grouplando.de can u integrate that into your previous response?
- Assistant
Sure! Here is the updated nginx configuration that uses the domain
grouplando.de:bashhttp { server { listen 80; server_name grouplando.de; location /api { proxy_pass http://spring_boot_api:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { proxy_pass http://react_app:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }With this configuration, requests to
grouplando.de/apiwill be proxied to the Spring Boot API and all other requests togrouplando.dewill be proxied to the React app. - User
How can i add a subdomain that redirects to another set of spring boot api and react app?
- Assistant
You can add another server block in the nginx configuration to handle the subdomain. For example, if you want to add a subdomain
admin.grouplando.dethat redirects to a separate set of Spring Boot API and React app, you can do the following:bash