B
B
BloodVIRUS2019-08-21 13:41:50
PHP
BloodVIRUS, 2019-08-21 13:41:50

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

6 answer(s)
I
Ivan Shumov, 2019-08-21
@inoise

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

T
ThunderCat, 2019-08-21
@ThunderCat

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.

S
Sergey Sokolov, 2019-08-21
@sergiks

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.

K
ky0, 2019-08-21
@ky0

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.

S
Supme, 2019-08-21
@Supme

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.

B
Boris Syomov, 2019-08-21
@kotomyava

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 question

Ask a Question

731 491 924 answers to any question