I have a docker-container running Nginx and i need to get the Version of Nginx in one of my php files. I tried using docker exec nginx_container nginx -v and it’s works only in terminal, it doesn’t return the $output.
Does someone know a properway to solve this?
2
Answers
If your nginx serves static files, you can make a request for one of those and then look at the
Server
header in the response.To illustrate, run nginx and make a request
The response will include the Nginx version in the
Server
header. On my machine, it’sServer: nginx/1.23.0
.Here is a small example (it’s been a while since I’ve used PHP, so there is probably a better way of doing this):
Result:
In my case there is no version information because we have turned off the version information using:
If you are running PHP in the same docker container you can just ignore the curl and run the command through php using
shell_exec
: