Nginx configuration parameters

Source: Internet
Author: User
Tags epoll

Check whether the nginx configuration file is correct

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

-C configuration file path

-G Set global directives. (version> = 0.7.4)

-T: Check whether the file is correct or not.

-V Print version.

-V Print nginx version, compiler version and configure parameters.

If-with-debug compilation is used during compilation, you can also use error_log file [debug_core | debug_http | debug_event…] To obtain the debug information.

Control Nginx by Signal

Nginx supports the following signals:

Description

The TERM and INT are used to quickly close the program and stop the request being processed.

After QUIT finishes processing the current request, close the program

HUP reloads the configuration, starts a new working process, and closes the process. This operation will not interrupt the request.

USR1 re-opens the log file to switch logs. For example, a new log file is generated every day.

USR2 smooth upgrade executable program

WINCH calmly closes the Working Process

There are two ways to control Nginx through these signals. The first is to use nginx under the logs directory. pid: view the ID of the currently running Nginx process. Use kill-XXX <pid> to control Nginx. XXX indicates the signal name listed in the preceding table. If there is only one Nginx process in your system, you can also run the killall command, for example, run killall-s HUP nginx to re-load the configuration of Nginx.

Configuration:

use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];

FreeBSD uses kqueue and epoll for Linux.

Worker_connections number the maximum number of connections per worker

Maxclient = work_processes * worker_connections

Currently, nginx upstream supports four allocation methods.

1. Default polling)

Each request is distributed to different backend servers one by one in chronological order. If the backend servers are down, they can be removed automatically.

2. weight

Specify the round-robin probability. weight is proportional to the access ratio, which is used when the backend server performance is uneven.

2. ip_hash

Each request is allocated according to the hash result of the access ip address, so that each visitor accesses a backend server at a fixed time, which can solve the session problem.

3. fair third party)

Requests are allocated based on the response time of the backend server. Requests with short response time are prioritized.

4. url_hash third-party)

Requests are allocated based on the hash result of the access url so that each url is directed to the same backend server. The backend server is effective when it is cached.

Proxy

You only need to add a virtual host to the nginx configuration file, and then add

\proxy_pass http://localhost:8000;

Server Load balancer:

You only need to add

Upstream tgcluster {# define the Ip address and device status of the Server Load balancer Device

Ip_hash;

Server 127.0.0.1: 9090 down;

Server 127.0.0.1: 8080 weight = 2;

Server 127.0.0.1: 6060;

Server 127.0.0.1: 7070 backup;

}

Add

Proxy_pass http: // tgcluster /;

The status of each device is set:

1. down indicates that the server before a ticket is not involved in the load

2. The default weight value is 1. The larger the weight value, the larger the load weight.

3. max_fails: the default number of failed requests is 1. If the maximum number of failed requests is exceeded, an error defined by the proxy_next_upstream module is returned.

4. fail_timeout: The pause time after max_fails fails.

5. backup: Requests the backup machine when all other non-backup machines are down or busy. Therefore, this machine is under the least pressure.

Nginx supports setting multiple groups of server Load balancer instances for unused servers.

Client_body_in_file_only is set to On. You can use the client post data record in the file for debugging.

Client_body_temp_path: Set the directory of the record file to a maximum of three levels.

Location matches the URL. You can perform redirection or perform new proxy load balancing.

FASTCGI Configuration:

Save the following content as a fastcgi_params file and save it to Ubuntu under/usr/local/nginx/conf, which can be saved under/etc/nginx ), he set basic environment variables for our FastCGI module:

# Fastcgi_params

Fastcgi_param GATEWAY_INTERFACE CGI/1.1;

Fastcgi_param SERVER_SOFTWARE nginx;

Fastcgi_param QUERY_STRING $ query_string;

Fastcgi_param REQUEST_METHOD $ request_method;

Fastcgi_param CONTENT_TYPE $ content_type;

Fastcgi_param CONTENT_LENGTH $ content_length;

Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

Fastcgi_param SCRIPT_NAME $ fastcgi_script_name;

Fastcgi_param REQUEST_URI $ request_uri;

Fastcgi_param DOCUMENT_URI $ document_uri;

Fastcgi_param DOCUMENT_ROOT $ document_root;

Fastcgi_param SERVER_PROTOCOL $ server_protocol;

Fastcgi_param REMOTE_ADDR $ remote_addr;

Fastcgi_param REMOTE_PORT $ remote_port;

Fastcgi_param SERVER_ADDR $ server_addr;

Fastcgi_param SERVER_PORT $ server_port;

Fastcgi_param SERVER_NAME $ server_name;

# PHP only, required if PHP was built with-enable-force-cgi-redirect

Fastcgi_param REDIRECT_STATUS 200;

Please pay special attention to bold line, PHP-CGI especially need this line of information to determine the location of the PHP file.

In addition, you need to open the cgi. fix_pathinfo option on the PHP-CGI configuration file Ubuntu which is located in/etc/php5/cgi/php. ini:

Cgi. fix_pathinfo = 1;

In this way, the SCRIPT_FILENAME variable can be used normally in php-cgi.

In the nginx configuration, configure the PHP file and execute it using the FastCGI process:

Server {

Index. php;

Root/usr/local/nginx/html;

Location ~ . *. Php $ {

Include/usr/local/nginx/conf/fastcgi_params; # Set it according to your saved path.

Fastcgi_index index. php;

Fastcgi_pass 127.0.0.1: 9000; # configure the address and port bound to FastCGI.

}

}

Notify Nginx to re-load the Configuration:

Kill-HUP 'cat/usr/local/nginx/logs/nginx. pid'

Ubuntu users can use the init Script: sudo/etc/init. d/nginx reload

Then start php-cgi-B 127.0.0.1: 9000

If No input file specified occurs, it indicates that there is a problem with the SCRIPT_FILENAME settings.

Use lighttpd's spawn-fcgi

Get http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2 # get Lighttpd source package

Tar-xvjf lighttpd-1.4.18.tar.bz2

Cd lighttpd-1.4.18

./Configure # compile

Make

Cp src/spawn-fcgi/usr/local/bin/spawn-fcgi # retrieve the spawn-fcgi Program

Next we can use spawn-fcgi to control the FastCGI process of php-cgi.

/Usr/local/bin/spawn-fcgi-a 127.0.0.1-p 9000-C 5-u www-data-g www-data-f/usr/bin/php-cgi

The parameter description is as follows:

-F <fcgiapp> specifies the location of the execution program of the process that calls FastCGI. It is set according to the PHP installed on the system.

-A <addr> bind to the address addr

-P <port> bind to port

-S <path> path bound to the unix socket

-C <childs> specifies the number of FastCGI processes generated. The default value is 5, which is used only for PHP)

-P <path> specifies the PID file path of the Generated Process

-U and-g FastCGI use the identity-u user-g user group) to run. www-data can be used in Ubuntu, and other configuration based on the situation, such as nobody and apache.

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.