Here is based on
Mac (MacOS 10.14.0)built-in
Nginx (1.12.0)and
PHP (PHP 7.1.23), mainly in the following aspects:
  • PHP – FPM configuration
  • Nginx configuration
  • Php-fpm /nginx process management



Mac nginx file path information

/usr/local/bin/nginx // symbolic link path /usr/local/var/ WWW // The default server root directory is /usr/local/etc/nginx // nginx configuration directory, nginx configuration files are located in this directory // nginx nginx // or: /usr/local/bin/nginxCopy the code

Php-fpm information


Default // php-fpm default configuration file /etc/php-fpm.d/www.conf.default // Process extension configuration file /usr/sbin/php-fpm/symbolic link pathCopy the code



Because it is Mac’s own Nginx and PHP, so omit the installation part, directly explain the operation and configuration

♢ Start nginx Server

through
nginx --version (or -v) View the version information of nginx

Start the nginx server (you can type nginx directly on the console, press Enter)

nginx
Copy the code

If no error is reported, type 127.0.0.1:8080 in your browser and see if a successful nginx startup message appears





♢ configure PHP – FPM

You can also use,
Php-fpm -v (or --version)Viewing version Information


If you start phP-fpm directly without specifying a configuration file, an error is reported, although in
/private/etc/ Directories have
php-fpm.conf.default Documents, but
php-fpmThe default for startup is
php-fpm.conf



Default copy php-fpm.conf from php-fpm.conf

cd /private/etc
cp php-fpm.conf.default php-fpm.confCopy the code



Open php-fpm.conf to find;
error_log = log/php-fpm.log This row, let me add a row down here
error_log = /usr/local/var/log/php-fpm.logTo specify an error log file to prevent errors
Then go to the php-fpm.d directory

cdPhp-fpm. d cp www.conf.default www.conf // The same copy is www.confCopy the code



Try to start php-fpm:

php-fpm
// or
php-fpm -DCopy the code



Verify whether the startup is successful
ps -ef | grep php-fpm Check whether phP-fpm is associated with the process



You can also specify configuration files for phP-fPM startup

PHP -fpm -c php.ini -y php-fpm.confCopy the code



PHP – FPM shutdown, restart, pass first
ps -ef | grep php-fpmFind the PID of the running PHP-fpm process and pass
kill -s signal PID To manage.
Signal:


signal
role
INT
Immediately terminate
QUIT
Smooth end
USR1
Re-open the log file
USR2
Restart (smoothly reloads all worker processes and reloads configuration and binary modules)

♢ configure nginx

In the default server configuration, find the commented PHP configuration, uncomment it, and change it to the following configuration (note the semicolon during the modification, otherwise nginx will start with an error).

location ~ \.php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; // Include fastcgi_params; }Copy the code

root htmlPoints to the default root directory of the nginx server
/usr/local/var/www, create an index. PHP and write a line of PHP code to verify service availability


cd /usr/local/var/www
echo "
        > index.phpCopy the code

Restart the nginx server

nginx -s reloadCopy the code



If no error is reported, it can be used
ps -ef | grep nginx Check to see if there are related processes to verify that nginx started successfully. Type in your browser:
127.0.0.1:8080 / index. PHP
If 11 of echo in PHP is displayed, the configuration is successful.


♢ Nginx Process Management

nginx -s stop       // fast shutdown
nginx -s quit       // graceful shutdown
nginx -s reload     // reloading the configuration file
nginx -sReopen // Reopen the log fileCopy the code

Nginx processes are divided into
Mater Processand
Worker process, the master process is responsible for managing the worker process, which is responsible for handling requests and possibly cache-related processes.


There are two working modes:
  • Single-process mode: Nginx has only one process that acts as both the master process and worker process
  • Multi-process mode: Nginx has one master process (and only one) and at least one worker process


The stop signal terminates all processes immediately, while the quit signal does not exit the process until the relevant service for the current request is completed.


When the configuration file is changed, it needs to use the Reload signal to notify Nginx to use the new configuration to start the new process. After receiving the Reload signal, the nginx master process will check the correct message of the new configuration file. If there is no problem, it will fork a new worker process based on the new configuration to receive the new request. A notification is sent to the worker process based on the configuration file to shut down. The process that receives the quit signal terminates the service first and then shuts down. If there is a problem, the master process rolls back the configuration and continues with the old configuration file.


You can also terminate the nginx worker process by using the kill command to send the corresponding command to the specified PID. Such as through
Ps - ef | grep nginx (or through the ps - ax | grep nginx)Find the nginx worker process ID

ps -ef | grep nginx 501 83158 1 0 4:44PM ?? 07:00.01 nginx: Master Process nginx 501 85683 83158 0 5:58PM?? 0:00. 00 nginx: the worker processCopy the code

Then, kill -s QUIT 85683 terminates the worker process with PID 85683 in the form of QUIT signal. Nginx mater process signals and functions:

signal
role
INT,TERM
Immediately terminate
QUIT
Smooth end
HUP
changing configuration, keeping up with a changed time zone (only for FreeBSD and Linux), starting new worker processes with a new configuration, graceful shutdown of old worker processes
USR1
Re-open the log file
USR2
upgrading an executable file
WINCH
graceful shutdown of worker processes