PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, June 24, 2022

[FIXED] How can I control nginx reverse proxy with my java app?

 June 24, 2022     api, java, nginx, nginx-config, reverse-proxy     No comments   

Issue

I use nginx reverse proxy with docker and want to automate my nginx configuration. For example, I want to tell my java app a domain/server_name (e.g. myapp.example.com) and a backend system. And my java app should tell nginx to configure that.

Is this possible or is there an alternative reverse proxy software with that functionality.


Solution

One way to achieve that would be to use a shared volume that both containers (the java container and the nginx container) can access and where the nginx configuration file is placed. This would also work if java is not in docker then it just needs access to the mapped folder.

Whenever you want to update the config just rewrite it and then trigger nginx to reload. There are mutliple ways to achieve this. Most easily by using

docker exec nginx-container-name nginx -s reload

e.g. via Java ProcessBuilder or the awesome Java Docker Project https://github.com/docker-java/docker-java.

Note: If you run java inside a docker container you have to map the docker socket inside the container (e.g. using -v /var/run/docker.sock:/var/run/docker.sock from shell).



Answered By - Julian
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing