nginx support LNMP
Install php-fpm
yum install php-fpm -y
Use the default configuration to the configuration file /etc/php-fpm.d/www.conf
Open the php configuration:
vim /etc/nginx/conf.d/defaults
location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
vim /etc/nginx/server.conf
LOCATION / { the root HTML; index index.php index.html index.htm; // support index.php page }
Modify fastcgi_parms
vim /etc/nginx/fastcgi_params
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 REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 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;
The above add the following line: fastcgi_param SCRIPT_FILENAME $ $ DOCUMENT_ROOT fastcgi_script_name;
php mysql support
# yum install php-mysql -y
Install mysql
# yum install mysql-server -y
Test Page
<?php $conn = mysql_connect('127.0.0.1','root',''); if ($conn) echo succ; else echo failure; mysql_close(); phpinfo(); ?>
Set the cache cluster dynamic content fastcgi protocol
http add context:
upstream upservers { server 10.0.0.102 max_fails=5 fail_timeout=1s weight=1; server 10.0.0.103 max_fails=5 fail_timeout=1s weight=1; } proxy_cache_path /cache/nginx/ levels=1:1 keys_zone=mycache:32m; fastcgi_cache_path /cache/fastcgi/ levels=1:1 keys_zone=fcgicache:32m inactive=3m max_size=1g;
server.conf defined in the configuration file location:
location ~ \.php$ { 46 fastcgi_cache fcgicache; 47 fastcgi_cache_valid 200 10m; 48 fastcgi_cache_valid 302 3m; 49 fastcgi_cache_valid any 1m; 50 51 root html; 52 fastcgi_pass 127.0.0.1:9000; 53 fastcgi_index index.php; 54 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 55 include fastcgi_params; 56 }
Other parameters introduced:
fastcgi_limit_rate: defining the content received from the upstream server rate
Syntax: fastcgi_limit_rate rate; Default: fastcgi_limit_rate 0; Context: http, server, location This directive appeared in version 1.7.7.
fastcgi_param: passing parameters to a rear end
Syntax: fastcgi_param parameter value [if_not_empty]; Default: — Context: http, server, location
fastcgi_store: the content saved to disk, not recommended to open, if you want to turn illustrate the performance is declining
Syntax: fastcgi_store on | off | string;
Default:
fastcgi_store off;
Context: http, server, location
LOCATION / Images / {
the root / Data / WWW;
error_page = 404 / $ FETCH URI;
}
LOCATION / FETCH / {
Internal;
fastcgi_pass backend: 9000;
...
fastcgi_store ON;
fastcgi_store_access User: RW Group: All RW: R & lt; fastcgi_temp_path / the Data / the TEMP; // Do not enable, should increase the size of the memory buffer
Alias / the Data / the WWW /;
}
Turn off caching
fastcgi_cache off;