Linux under Nginx configuration file (nginx.conf) configuration settings (Windows with Phpstudy integration)

Source: Internet
Author: User
Tags configuration settings unix domain socket nginx server pkill

Examples of Linux backup nginx.conf files:

cp/usr/local/nginx/nginx.conf/usr/local/nginx/nginx.conf-20171111 (date)

In the process list, look for the master process, whose number is the main process number.

View process

Cat/usr/local/nginx/nginx.pid

Reload the config file Linux command every time you finish modifying the Nginx file:

/USR/LOCAL/NGINX-T      //Verify that the configuration file is legitimate

If the nginx.conf configuration of the PID file storage path, the file is stored in the Nginx main process number with PID

Kill the process

kill-hup/usr/local/nginx/-hup main process number

Calmly stop Nginx

kill-quit/usr/local/nginx/nginx.pid  -quit main process number

Quick Stop Nginx

kill-term/usr/local/nginx/nginx.pid  

Forced Stop Nginx

Kill-9/usr/local/nginx/nginx.pid    -9 main process number   

Process if it is the same process name can use the Pkill command

Pkill  

Multiple processes if the same process name can be used with the Killall command

Killall  

Start

/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf

Stop/Reload

/usr/local/nginx/nginx-s Stop (Quit,reload)

The beginning of the "http {}" block is the same as the beginning of the configuration file and no modification is required for the standard configuration. Here we need to focus on these elements.

The connection time-out, 1 minutes, can be set depending on the time required for the request (for example, background import):

Keepalive_timeout  

Use Nginx server if you encounter timeou conditions, you can set parameters as follows, using fastcgi:

Fastcgi_connect_timeout;   ;    ;   Send a request

These two options.
Fastcgi_read_timeout is the time-out period of the entire process that the FASTCGI process sends response to the NGINX process
Fastcgi_send_timeout is the time-out of the entire process that the Nginx process sends a request to the FASTCGI process
Both options are seconds (s) by default and can be manually specified as minutes (m), hours (h), etc.

Buffer mechanism

For Response,nginx from FastCGI Server, buffer it into memory and send it to the client browser in turn. The size of the buffer is controlled by two values of fastcgi_buffers and fastcgi_buffer_size.
For example, the following configuration:

Fastcgi_buffers      # control Nginx create up to 8 buffers with a size of 4K fastcgi_buffer_size  # processing The size of the first buffer when Response is not included in the former

The maximum memory buffer size that can be created by total is 8*4k+4k = 36k
When Response is less than or equal to 36k, all of the data is, of course, processed in memory. What if Response is greater than 36k? This is the role of fastcgi_temp. The extra data is temporarily written to the file and placed under this directory.

# The default value is twice times the fastcgi_buffers.  # How much data blocks are used when writing to the cache file, and the default value is twice times the fastcgi_buffers. 

Fastcgi_cache indicates that the FASTCGI cache is turned on and assigned a name. Enabling caching is useful to effectively reduce the load on the CPU and prevent 502 errors from occurring. But opening the cache can also cause a lot of problems, depending on the situation.

The fastcgi_cache_valid is used to specify the cache time for the answer code. The values in the instance indicate that the 200 and 302 responses are cached for one hours, the 301 answer cache is 1 days, and the other responses are cached for 1 minutes.

Gzip on using GIZP compression is not without cost. It also increases CPU usage while reducing bandwidth. The Gzip_cop_level parameter value range 1-9, 9 for the most CPU and 1 for the minimum CPU, the default value is 1

Virtual Machine Server Configuration
Examples of configuration files:

Server {Listen80;#The listen instruction tells Nginx to listen for connections on a specific hostname,ip or TCP port. By default, the HTTP service runs on port 80server_name host.hzgapi.com host.hzgapi.com;#instructions can be set up based on the domain name of the virtual host, according to the content of the request header, an IP server can configure multiple domain namesRoot"D:/www/hzgapi";#instruction Specifies the definition of the topmost directory (path)Location/{index index.html index.htm index.php; #AutoIndex on;} location ~ \.php (.*)${Fastcgi_pass127.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$fastcgi _path_info; Fastcgi_param path_translated$document _root$fastcgi_path_info;        Include Fastcgi_params; }}

Location configuration
For a particular request, once nginx matches a location to process. The response of the request is then determined by the instructions in the location block. In this example the Chinese file root (doucument root) is located in the html/directory. According to Nginx installation directory/usr/local/nginx (can not be used), the full path of this location is/usr/local/nginx/html.
The index directive tells Nginx which resource to use if the request does not have a 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. Other requests, Nginx will use the first location block to handle.

There are two ways of interprocess communication between the Fastcgi_pass directive Nginx and the PHP-FPM:
Nginx Fastcgi_pass Listening Port UNIX socket and TCP socket differences, TCP and UNIX domain socket method, TCP is to use TCP port connection 127.0.0.1:9000. PHP 5.3 or later changes TCP to the socket mode configuration method:
Modify Php-fpm.conf (/usr/local/php/etc/php-fpm.conf) according to the path where the direct installation files are located:

; listen = 127.0.0.1:9000=/dev/shm/php-cgi.sock

Modify the configuration of the Nginx configuration file server segment to change the HTTP mode to socket mode.
Restart PHP-FPM and Nginx (CentOS system command)

service Nginx restartservice php--AL/DEV/SHM

Theoretically, the UNIX socket does not take the network, the efficiency is higher, but the stability is not very ideal.

Fastcgi_param directives define variables and assign values.
Fastcgi_index scope: HTTP, server, location. When the request is/ends, the request is passed to the set of index.php file processing.
Fastcgi_split_path_info Scope: Location. Nginx does not get the value of Path_info by default and assigns a value to $fastcgi_path_info by specifying a regular expression defined by Fastcgi_split_path_info.
Its regular expression must have two captures.
The first captured value is re-assigned to the $fastcgi_script_name variable.
The second captured value is re-assigned to the $fastcgi_path_info variable.
Fastcgi_param script_filename $document _root$fastcgi_script_name;//script file request path/directory
$document _root parameters are defined by the root HTML line, the default is in/etc/nginx/html/, so the HTML is changed to the site root directory is normal.
Include directives are include files

Define the users and user groups that Nginx runs (which you can omit by definition).
User www www;

The number of Nginx processes is recommended to be equal to the total CPU core number (self-defined ignore).
Worker_processes 8;

Global error log definition type, [Debug | info | notice | warn | error | crit] (self-defined can be ignored)
Error_log/usr/local/nginx/logs/error.log info;

Process PID file (can be ignored according to the direct definition)
Pid/usr/local/nginx/logs/nginx.pid;

Linux under Nginx configuration file (nginx.conf) configuration settings (Windows with Phpstudy integration)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.