Answer the question
In order to leave comments, you need to log in
How to reload nginx using php?
Hello. I continue to fight for the ability for users to connect to their domains (and connect to them https). I resigned myself to the fact that I can’t do without a single config (as was the case in my previous question), and absolutely for each site you need to create your own config.
But the question is, how can I restart NGINX from a php script? exec doesn't work, and I don't want to use it. I think it's extremely unsafe.
What other options might exist?
Here he would look for configs on the fly, without rebooting ..
Answer the question
In order to leave comments, you need to log in
Don't do bullshit. There is such a wonderful thing as IaC (Infrastructure as Code). There are a lot of tools for this, and access to this can already be done through php because these tools have their own API. Prepare configurations, update them to php and restart deployment. Everyone is happy
Well, there are many options, for example:
Create a restart.ngx file from puff when you need to restart the server, from the cron every minute you pull the bash script to restart the server if the file exists + delete the file. Physically puff does not pull the system.
Questions of stability of the system and other "security" look locally.
You can just do a cron every 15 minutes not to restart nginx itself, but only to re-read the configs.
in the crontab for root
, with checking the correctness of the configs:
It is even better to make a bash script, where, if the config test fails, send an email with exclamations.
I suggest you look towards inotify and similar things. But in general - within the framework of one web server, this is problematic, because if at least one client has a crookedness, nginx will not rise. Accordingly, verification is needed with a subsequent rollback.
It is much more logical to provide each user with their own instance of the web server.
With changes, we write the file to a special directory. Subscribing to a file system event for changing a directory. By changing - nginx -t and in the case of a fakap, sending a message to all those involved, in case of a good completion of the reload angie, it is a reload, not a restart.
Analyze how hosting control panels work and are made before you make your own square wheel bike.
Usually, there is a separate web interface, and a separate toolkit working with elevated privileges, connected through some kind of interprocess communication, in the simplest case, for example, through a database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question