As a web server: Compared with Apache, Nginx uses fewer resources, supports more concurrent connections, and reflects higher efficiency.
As a [Load Balancing] (https://cloud.tencent.com/product/clb?from=10680) server: Nginx can directly support Rails and PHP internally, and can also support external services as an HTTP proxy server. Nginx is written in C and is much better than Perlbal in terms of system resource overhead and CPU usage efficiency.
As a mail proxy server: Nginx is also a very good mail proxy server (one of the earliest purposes of developing this product is also as a mail proxy server), Last/fm describes successful and wonderful experience.
Nginx installation is very simple, and the configuration file is very concise (it can also support perl syntax). Nginx supports the smooth loading of new configurations, and can also upgrade the software version without interruption of service.
The LNMP architecture is therefore very popular, especially the emergence of VPS and cloud hosting, which has further promoted the development and integration of LNMP's architecture. Since php5.4, the php-fpm method has been natively supported. PHP-FPM is a PHP FastCGI manager, which is no longer a third-party package. PHP-FPM provides a better way of managing PHP processes, which can effectively control memory and processes, and can smoothly reload PHP configuration, which is better than spawn-fcgi Has more advantages.
Ready to work:
Minimize installation of centos6.5
Create a package directory to store
mkdir -p /usr/local/src/
Clean up installed packages
rpm -e httpd
rpm -e mysql
rpm -e php
yum -y remove httpd
yum -y remove mysql
yum -y remove php
# Search apache package
rpm -qa http*
# Force uninstall apache package
rpm -e --File name queried by nodeps
# Check whether the uninstallation is clean
rpm -qa|grep http*
selinux may cause the compilation and installation to fail, let's disable it first. Permanently disabled, need to restart to take effect
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/config
Temporarily disable, no need to restart setenforce 0
Install necessary tools
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof
Create users and user groups for mysql according to the standard
Create group
groupadd mysql
Create a user, do not allow login and do not create the home directory
useradd -s /sbin/nologin -g mysql -M mysql
Check created user
tail -1/etc/passwd
After centos minimal installation, there will be mysql libraries, so uninstall first!
Check installation
rpm -qa|grep mysql
Force uninstall
rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps
Starting from version 5.5 of MySQL, the way of compiling and configuring through ./configure has been cancelled and replaced by cmake tool. Therefore, we must first compile and install the cmake tool in the system.
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
tar zxvf cmake-2.8.12.2.tar.gz
cd cmake-2.8.12.2./configure
make && make install
Use cmake to compile and install mysql5.6.17
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
tar zxvf mysql-5.6.17.tar.gz
cd mysql-5.6.17
cmake \
- DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
- DMYSQL_DATADIR=/usr/local/mysql/data \
- DSYSCONFDIR=/etc \
- DWITH_MYISAM_STORAGE_ENGINE=1 \
- DWITH_INNOBASE_STORAGE_ENGINE=1 \
- DWITH_MEMORY_STORAGE_ENGINE=1 \
- DWITH_READLINE=1 \
- DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
- DMYSQL_TCP_PORT=3306 \
- DENABLED_LOCAL_INFILE=1 \
- DWITH_PARTITION_STORAGE_ENGINE=1 \
- DEXTRA_CHARSETS=all \
- DDEFAULT_CHARSET=utf8 \
- DDEFAULT_COLLATION=utf8_general_ci \
- DMYSQL_USER=mysql \
- DWITH_DEBUG=0 \
- DWITH_SSL=system
make && make install
Modify /usr/local/mysql permissions
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
About my.cnf configuration file:
When starting the MySQL service, it will search for my.cnf in a certain order, first in the /etc directory, if not found, it will search for "$basedir/my.cnf", which is /usr/local/mysql/my in the installation directory. cnf, this is the default location of the configuration file for the new version of MySQL! Note: After the minimal installation of CentOS 6.x operating system is completed, there will be a my.cnf in the /etc directory, and this file needs to be renamed to another name. Such as: /etc/my.cnf.bak, otherwise, this file will interfere with the correct configuration of MySQL installed from the source code, causing it to fail to start. Since we have uninstalled the mysq library after the minimal installation is complete, there is no need to operate.
Enter the support-files directory
cd support-files/
If there is my.cnf please backup
mv /etc/my.cnf /etc/my.cnf.bak
If you want, you can also copy the configuration file to etc.
cp my-default.cnf /etc/my.cnf
Execute the initial configuration script, create the database and table that comes with the system, pay attention to the path of the configuration file
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Copy the support-files service script in the MySQL installation directory to the init.d directory
# Copy script
cp support-files/mysql.server /etc/init.d/mysqld
# Grant permissions
chmod +x /etc/init.d/mysqld
Set boot up
chkconfig mysqld on
Start MySQL
service mysqld start
or
/etc/init.d/mysql start
After MySQL5.6.x is successfully started, root has no password by default, and we need to set the root password. Before setting, we need to set the PATH first, otherwise, we can not directly call mysql
modify/etc/profile file
vi /etc/profile
Add at the end of the file
PATH=/usr/local/mysql/bin:$PATH
export PATH
Make the configuration effective immediately
source /etc/profile
Login test, the default is no password, you can enter directly by pressing Enter
mysql -uroot -p
Set mysql password
/usr/local/mysql/bin/mysqladmin -uroot -p password 'Your password'
Log in to command line mode
mysql -uroot -p
View users
select user,host from mysql.user;
Delete unnecessary users
drop user ""@localhost;
drop user ""@c65mini.localdomain;
drop user [email protected];
drop user root@'::1';
Grant account remote access permissions
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'Your password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'Your password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'c65mini.localdomain' IDENTIFIED BY 'Your password' WITH GRANT OPTION;
About deleting MySQL's default root user reference: http://blog.chinaunix.net/uid-16844903-id-3377690.html
Some other information query: Check the mysql version
mysql -uroot -p"password"-e "select version();"
Verify the mysql installation path
ls -ld /usr/local/mysql/
Install PHP5.5.12
Install dependencies
The libiconv library provides an iconv() function for applications that need to be converted to implement the conversion from one character code to another. Error message: configure: error: Please reinstall the iconv library.
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14./configure --prefix=/usr/local/libiconv
make && make install
cd ..
libmcrypt is an extension library for encryption algorithms. Error prompt: configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.
wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8./configure
make && make install
cd ..
Mhash is an irreversible PHP encryption extension library based on the principle of discrete mathematics, which is not enabled by default. mhash can be used to create check values, message digests, message authentication codes, and save key information without original text. Error prompt: configure: error: "You need at least libmhash 0.8.15 to compile this program. http://mhash .sf.net/"
wget http://hivelocity.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
tar jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9./configure
make && make install
cd ..
mcrypt is an important encryption support extension library in php. The Mcrypt extension library can implement encryption and decryption functions, that is, it can both encrypt plain text and restore cipher text.
wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8./configure
make && make install
cd ..
Compiling mcrypt may report an error: configure: error: *** libmcrypt was not found
vi /etc/ld.so.conf
Add in the last line
/usr/local/lib/
Loading
ldconfig
Compiling mcrypt may report an error: /bin/rm: cannot remove `libtoolT': No such file or directory
Modify the configure file, put RM='$RM'Change to RM='$RM -f'here$There must be a space after RM. If there is no space after it, and the minus sign is connected directly, an error will still be reported.
Officially start compiling php!
wget http://mirrors.sohu.com/php/php-5.5.12.tar.gz
tar zxvf php-5.5.12.tar.gz
cd php-5.5.12./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install
Modify the fpm configuration php-fpm.conf.default file name
mv /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
Copy the php.ini configuration file
cp php.ini-production /usr/local/php/etc/php.ini
Copy the php-fpm startup script to init.d
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
Grant execution permissions
chmod +x /etc/init.d/php-fpm
Add as startup item
chkconfig --add php-fpm
Set boot up
chkconfig php-fpm on
According to the standard, create a specified user and group for php-fpm
Create group
groupadd www
Create a user, do not allow login and do not create the home directory
useradd -s /sbin/nologin -g www -M www
Start php-fpm immediately
service php-fpm start
# or
/etc/init.d/php-fpm start
Go back to the /usr/local/src/ directory
For the dependencies required by nginx, generally we need to install pcre and zlib first. The former is for rewriting and the latter is for gzip compression. If the system has yum installed these libraries, it doesn't matter, there is no need to uninstall them. Just compile and install the latest version directly. In order to complete the compilation at one time, first prepare to compile the following dependencies!
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35./configure
make && make install
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8./configure
make && make install
Free to choose whether to compile
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
tar -zxvf openssl-1.0.1g.tar.gz
According to Google, the ngx_pagespeed module has been used in production environments by some customers, including CDN provider MaxCDN. According to its report, the module has reduced the average page load time by 1.57 seconds, the bounce rate by 1%, and exit The percentage dropped by 2.5%". WordPress hosting provider ZippyKid said that after using NGINX's PageSpeed, "page size has been reduced by 75% and page rendering time has increased by 50%."
wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.8.31.2-beta.zip
unzip v1.8.31.2-beta.zip
cd ngx_pagespeed-1.8.31.2-beta/
wget https://dl.google.com/dl/page-speed/psol/1.8.31.2.tar.gz
tar -xzvf 1.8.31.2.tar.gz
5、 Use the TCMalloc tool provided by google-perftools to optimize nginx and mysql
TCMalloc (google-perftools) is used to optimize multi-threaded applications written in C++, which is faster than glibc 2.3 malloc. This module can be used to make MySQL's memory usage more stable under high concurrency.
TCMalloc is one of the tools of google-perftools, which is used to optimize the efficiency and speed of memory allocation, and to help control the use of memory in high concurrency situations.
In the mysql and nginx performance optimization solutions, most tutorials use the TCMalloc tool provided by google-perftools. TCMalloc is much more efficient and faster than malloc in memory allocation.
Error prompt: configure: error: No frame pointers and no libunwind. The compilation will fail is because you started to compile gperftools without installing the libunwind library, so you must first libunwind
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
tar zxvf libunwind-1.1.tar.gz
cd libunwind-1.1
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
According to the official instructions, the latest version must be selected.
wget https://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.2.tar.gz
tar zxvf gperftools-2.2.tar.gz
cd gperftools-2.2./configure
make && make install
The preparations are complete, now install nginx! , The library relationship prepared earlier is added here, pay attention to the path!
wget http://nginx.org/download/nginx-1.7.0.tar.gz
tar zxvf nginx-1.7.0.tar.gz
cd nginx-1.7.0./configure \
- - user=www \
- - group=www \
- - prefix=/usr/local/nginx \
- - with-http_stub_status_module \
- - with-http_ssl_module \
- - with-http_gzip_static_module \
- - with-pcre=/usr/local/src/pcre-8.35 \
- - with-zlib=/usr/local/src/zlib-1.2.8 \
- - with-openssl=/usr/local/src/openssl-1.0.1g \
- - add-module=/usr/local/src/ngx_pagespeed-1.8.31.2-beta \
- - with-google_perftools_module
cd ..
6、 Modify the nginx.conf configuration file
Open the ngx_pagespeed module in the server block
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
location ~".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+"{ add_header """";}
location ~"^/ngx_pagespeed_static/"{}
location ~"^/ngx_pagespeed_beacon$"{}
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all;}
location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all;}
location /ngx_pagespeed_message { allow 127.0.0.1; deny all;}
location /pagespeed_console { allow 127.0.0.1; deny all;}
Enable google_perftools tuning support
# First create tcmalloc in tmp
mkdir /tmp/tcmalloc
# Grant permissions
chmod 0777/tmp/tcmalloc/
# Generally we add below pid
google_perftools_profiles /tmp/tcmalloc;
# It must be restarted, and loading the configuration in time will not take effect. There is under the nginx startup restart script.
service nginx restart
Verify the running status of tcmalloc, this is the effect of only opening one worker_processes
[ root@bin2aliyun ~]# lsof -n|grep tcmalloc
nginx 24471 www 16w REG 202,10821485/tmp/tcmalloc/.24471
Using TCMalloc (google-perftools) can be used to make MySQL more stable in memory usage under high concurrency.
In mysqld_safe script file started to join
vi /usr/local/mysql/bin/mysqld_safe
LD_PRELOAD="/usr/local/lib/libtcmalloc.so"
service mysql restart
Use xcache to optimize php performance.
wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz
tar zxvf xcache-3.1.0.tar.gz
cd xcache-3.1.0/usr/local/php/bin/phpize
. /configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install
Copy xcache viewer to the website directory
cp htdocs//home/wwwroot/htdocs/xcache -rf
cat >>/usr/local/php/etc/php.ini<<EOF
[ xcache-common];Pay attention to the path
extension =/usr/local/php/lib/php/extensions/no-debug-zts-20121212/xcache.so
[ xcache.admin]
xcache.admin.enable_auth = on
xcache.admin.user ="admin"
xcache.admin.pass ="e10adc3949ba59abbe56e057f20f883e";run: echo -n "password"|md5sum |awk '{print $1}'Calculate the MD5 encrypted password
; Replace xcache.admin.pass=Value of
[ xcache]
xcache.shm_scheme ="mmap"
xcache.size = 64M
xcache.count =1
xcache.slots = 8K
xcache.ttl =3600
xcache.gc_interval =60
xcache.var_size = 16M
xcache.var_count =1
xcache.var_slots = 8K
xcache.var_ttl =3600
xcache.var_maxttl =0
xcache.var_gc_interval =300
xcache.readonly_protection = Off
xcache.mmap_path ="/dev/zero"
xcache.coredump_directory ="/tmp/phpcore"
xcache.coredump_type =0
xcache.disable_on_crash = Off
xcache.experimental = Off
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[ xcache.coverager]
xcache.coverager = Off
xcache.coverager_autostart = On
xcache.coveragedump_directory ="/tmp/pcov"
EOF
Install phpmyadmin
wget http://iweb.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.2/phpMyAdmin-4.2.2-all-languages.tar.gz
tar zxvf phpMyAdmin-4.2.2-all-languages.tar.gz
mv phpMyAdmin-4.2.2-all-languages phpmyadmin
cd phpMyAdmin
mkdir config
chmod o+rw config
mv config/config.inc.php config.inc.php
chmod o-rw config.inc.php
rm -rf config
nginx restart, start, load script
vi /etc/init.d/nginx
#! /bin/sh
#
# nginx -this script starts and stops the nginx daemon
#
# chkconfig:-8515
# description: Nginx is an HTTP(S) server,HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config:/etc/nginx/nginx.conf
# config:/etc/sysconfig/nginx
# pidfile:/var/run/nginx.pid
# Source function library../etc/rc.d/init.d/functions
# Source networking configuration../etc/sysconfig/network
# Check that networking is up.["$NETWORKING"="no"]&& exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
sysconfig="/etc/sysconfig/$prog"
lockfile="/var/lock/subsys/nginx"
pidfile="/usr/local/nginx/logs/nginx.pid"
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"[-f $sysconfig ]&&. $sysconfig
start(){[-x $nginx ]|| exit 5[-f $NGINX_CONF_FILE ]|| exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0]&& touch $lockfile
return $retval
} stop(){
echo -n $"Stopping $prog: "
killproc -p $pidfile $prog
retval=$?
echo
[ $retval -eq 0]&& rm -f $lockfile
return $retval
} restart(){
configtest_q ||return6
stop
start
} reload(){
configtest_q ||return6
echo -n $"Reloading $prog: "
killproc -p $pidfile $prog -HUP
echo
} configtest(){
$nginx -t -c $NGINX_CONF_FILE
} configtest_q(){
$nginx -t -q -c $NGINX_CONF_FILE
} rh_status(){
status $prog
} rh_status_q(){
rh_status >/dev/null2>&1}
# Upgrade the binary with no downtime.upgrade(){
local oldbin_pidfile="${pidfile}.oldbin"
configtest_q ||return6
echo -n $"Upgrading $prog: "
killproc -p $pidfile $prog -USR2
retval=$?
sleep 1if[[-f ${oldbin_pidfile}&&-f ${pidfile}]]; then
killproc -p $oldbin_pidfile $prog -QUIT
success $"$prog online upgrade"
echo
return0else
failure $"$prog online upgrade"
echo
return1
fi
}
# Tell nginx to reopen logs
reopen_logs(){
configtest_q ||return6
echo -n $"Reopening $prog logs: "
killproc -p $pidfile $prog -USR1
retval=$?
echo
return $retval
} case"$1"in
start)
rh_status_q && exit 0
$1;;
stop)
rh_status_q || exit 0
$1;;
restart|configtest|reopen_logs)
$1;;
force-reload|upgrade)
rh_status_q || exit 7
upgrade
;;
reload)
rh_status_q || exit 7
$1;;
status|status_q)
rh_$1;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;*)
echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
exit 2
esac
Note that you need to grant execution permissions: chmod +x /etc/init.d/nginx
Optimized nginx.cnf configuration file
user www www;
worker_processes 1;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;
# Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
# limit_zone crawler $binary_remote_addr 10m;
server_tokens off;
# log format
log_format access '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for';
server
{
listen 80;
server_name www.cnhzz.com;
index index.html index.htm index.php;
root /home/wwwroot/htdocs;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;}
location /status {
stub_status on;
access_log off;}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;}
location ~.*\.(js|css)?$
{
expires 12h;}
access_log /home/wwwlogs/access.log access;}
include vhost/*.conf;
}
Added ngx_pagespeed google_perftools for virtual hosts as needed
log_format www.cnhzz.com '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for';
server
{
listen 80;
server_name www.cnhzz.com cnhzz.com;if($host !='www.cnhzz.com'){
rewrite ^/(.*)$ http://www.cnhzz.com/$1 permanent;}
index index.php index.html index.htm;
root /home/wwwroot/www.cnhzz.com;
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
log_format www.cnhzz.com '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for';
server
{
listen 80;
server_name www.cnhzz.com cnhzz.com;if($host !='www.cnhzz.com'){
rewrite ^/(.*)$ http://www.cnhzz.com/$1 permanent;}
index index.php index.html index.htm;
root /home/wwwroot/www.cnhzz.com;
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
location ~"\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+"{ add_header """";}
location ~"^/ngx_pagespeed_static/"{}
location ~"^/ngx_pagespeed_beacon$"{}
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all;}
location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all;}
location /ngx_pagespeed_message { allow 127.0.0.1; deny all;}
location /pagespeed_console { allow 127.0.0.1; deny all;}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;}
location ~.*\.(js|css)?$
{
expires 12h;}
access_log /home/wwwlogs/www.cnhzz.com.log www.cnhzz.com;}
php-fpm optimization, note that an fpm process is about 20M, my machine is a cloud host with small memory, so just open two. If the memory is large, it is converted according to the situation.
vi php-fpm.conf
pm = dynamic
pm.max_children =20
pm.start_servers =2
pm.min_spare_servers =1
pm.max_spare_servers =6
request_terminate_timeout =100
Recommended Posts