Configuration settings in the Nginx configuration file (nginx. conf) in linux (phpstudy integration for windows ),
Example of backing up nginx. conf files in linux:
Cp/usr/local/nginx. conf/usr/local/nginx. conf-20171111 (date)
Find the master process in the process list. Its number is the master process number.
ps -ef | grep nginx
View Processes
cat /usr/local/nginx/nginx.pid
The linux Command of the configuration file needs to be reloaded after each nginx file is modified:
/Usr/local/nginx-t // verify that the configuration file is valid
If the pid file storage path is configured for nginx. conf, the file is stored as the Nginx main process number, and the pid is used.
Kill Process
Kill-HUP/usr/local/nginx. pid kill-HUP master process number
Stop Nginx with ease
Kill-QUIT/usr/local/nginx. pid kill-QUIT master process number
Stop Nginx quickly
Kill-TERM/usr/local/nginx. pid kill-TERM master process number
Force stop Nginx
Kill-9/usr/local/nginx. pid kill-9 master process number
If the process name is the same, run the pkill command.
pkill nginx
If multiple processes have the same process name, run the Killall command.
killall nginx
Start
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Stop/reload
/usr/local/nginx/nginx -s stop(quit,reload)
The opening profile of the "http {}" block starts with the same standard configuration and does not need to be modified. Here we need to focus on these elements
Connection Timeout: 1 minute. The specific time can be set based on the time required by the request (for example, background import:
keepalive_timeout 600;
If the nginx server encounters timeou, you can set the following parameters by using fastcgi:
Fastcgi_connect_timeout 75; Link fastcgi_read_timeout 600; read fastcgi_send_timeout 600; send a request
These two options.
Fastcgi_read_timeout refers to the timeout time for the entire process from the fastcgi process to send response to the nginx process.
Fastcgi_send_timeout refers to the time-out period during which the nginx process sends a request to the fastcgi process.
The two options are second (s) by default, which can be manually specified as minute (m), hour (h), etc.
Buffer MECHANISM
For the Response from the FastCGI Server, Nginx caches it into the memory and sends it to the client browser in sequence. The buffer size is controlled by the fastcgi_buffers and fastcgi_buffer_size values.
For example, the following Configuration:
Fastcgi_buffers 8 4 K; # control nginx to create a maximum of 8 4 K buffer zones fastcgi_buffer_size 4 K; # the size of the first buffer zone when processing Response, not included in the former
The maximum memory buffer size that can be created in total is 8*4 K + 4 K = 36 k
When the Response is smaller than or equal to 36 KB, all data is processed in the memory. What if Response is greater than 36 k? The role of fastcgi_temp lies in this. The extra data will be temporarily written to the file and placed under this directory.
Fastcgi_busy_buffers_size # The default value is twice that of fastcgi_buffers. Fastcgi_temp_file_write_size # the size of the data block used to write the cached file. The default value is twice that of fastcgi_buffers.
Fastcgi_cache indicates that FastCGI cache is enabled and a name is specified for it. Enabling cache is very useful, which can effectively reduce the CPU load and prevent 502 errors. However, enabling caching also causes many problems, depending on the actual situation.
Fastcgi_cache_valid is used to specify the cache time for the response code. The value in the instance indicates that the 200 and 302 responses are cached for one hour, the 301 responses are cached for one day, and other responses are cached for one minute.
Gzip on uses gizp to compress. The CPU usage is also increased while the bandwidth is reduced. The value range of the gzip_cop_level parameter is 1-9, 9 indicates the maximum CPU usage and 1 indicates the Minimum CPU usage. The default value is 1.
Virtual Machine server Configuration
Configuration File example:
Server {listen 80; # The listen Command tells nginx to listen for connections in a specific hostname, ip address, or tcp port. By default, the http service runs on port 80, server_name host.hzgapi.com; # The command can be used to set a domain name-based VM based on the content of the request header, A server with an ip address can be configured with multiple domain names root "D:/www/hzgapi"; # specify the command as the definition (PATH) of the top directory location/{index index.html index.htm index. php; # autoindex on;} location ~ \. Php (. *) $ {fastcgi_pass 127.0.0.1: 9000; # fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index. php; fastcgi_split_path_info ^ ((? U). + \. php )(/?. +) $; Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; fastcgi_param PATH_INFO $ response; fastcgi_param PATH_TRANSLATED $ document_root $ response; include fastcgi_params ;}}
Location Configuration
For specific requests, once nginx matches a location. The response content of this request is determined by the commands in the location block. In this example, the document root (doucument root) is located in the html/directory. The full path of this location is/usr/local/nginx/html according to the nginx installation directory/usr/local/nginx (optional.
The index Command tells nginx which resource to use if the request contains no file name.
All requests ending with. php are processed by the second location block. The second statement block specifies a fastcgi handle for all requests. For other requests, nginx uses the first location block for processing.
Fastcgi_pass command Nginx and PHP-FPM Process Communication has two ways:
In Nginx, The fastcgi_pass listening port is different from the unix socket and tcp socket. The TCP and unix domain socket methods are compared. TCP uses the TCP port to connect 127.0.0.1: 9000. Php 5.3 and later versions change TCP to socket:
Modify the path of the php-fpm.conf (/usr/local/php/etc/php-fpm.conf) based on the direct installation file:
;listen = 127.0.0.1:9000listen = /dev/shm/php-cgi.sock
Modify the server Segment configuration of the nginx configuration file and change the http mode to the socket mode.
Restart php-fpm and nginx (centos system command)
service nginx restartservice php-fpm restartls -al /dev/shm
Theoretically, unix socket does not go through the network, which is more efficient, but the stability is not ideal.
The fastcgi_param command defines variables and assigns values.
Fastcgi_index scope: http, server, location. When a request ends with a slash (/), the request is passed to the configured index. php file for processing.
Fastcgi_split_path_info scope: location. Nginx does not get the PATH_INFO value by default. You must assign a value to $ fastcgi_path_info through the regular expression specified by fastcgi_split_path_info.
The regular expression must have two captures.
The first captured value is assigned to the $ fastcgi_script_name variable again.
The second captured value is assigned to the $ fastcgi_path_info variable again.
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; // path/directory of the script file request
The $ document_root parameter is defined by the root html line. The default value is/etc/nginx/html/. Therefore, it is normal to change html to the site root directory.
Include Commands include files
Define the users and user groups for running Nginx (you can ignore them if you define them ).
User www;
The number of nginx processes. We recommend that you set it to equal to the total number of CPU cores (ignore as defined by yourself ).
Worker_processes 8;
Global error Log definition type, [debug | info | notice | warn | error | crit] (can be ignored if you define it yourself)
Error_log/usr/local/nginx/logs/error. log info;
Process pid file (can be ignored according to direct definition)
Pid/usr/local/nginx/logs/nginx. pid;