作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。
作为负载均衡服务器:Nginx 既可以在内部直接支持Rails和PHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是cpu使用效率都比Perlbal要好的多。
作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。
Nginx安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。
建立一个软件包目录存放
mkdir-p/usr/local/src/
清理已经安装包
rpm-ehttpd rpm-eMysqL rpm-ePHP yum-yremovehttpd yum-yremoveMysqL yum-yremovePHP #搜索apache包 rpm-qahttP* #强制卸载apache包 rpm-e--nodeps查询出来的文件名 #检查是否卸载干净 rpm-qa|grephttP*
selinux可能会致使编译安装失败,我们先禁用它。永久禁用,需要重启生效
sed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/config
临时禁用,不需要重启setenforce 0
安装必备工具
yum-yinstallmakegccgcc-c++gcc-g77flexbisonfilelibtoollibtool-libsautoconfkernel-devellibjpeglibjpeg-devellibpnglibpng-devellibpng10libpng10-develgdgd-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglib2glib2-develbzip2bzip2-devellibeventlibevent-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-devellibidnlibidn-developensslopenssl-develgettextgettext-develncurses-develgmp-develpspell-develunziplibcaplsof
安装MysqL5.6.17
按照标准需要给MysqL创建所属用户和用户组
创建群组 groupaddMysqL 创建一个用户,不允许登陆和不创主目录 useradd-s/sbin/nologin-gMysqL-MMysqL 检查创建用户 tail-1/etc/passwd
centos最小化安装后,会有MysqL的库因此先卸载!
检查安装与否 rpm-qa|grepMysqL 强制卸载 rpm-eMysqL-libs-5.1.73-3.el6_5.x86_64--nodeps
MysqL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。 因此,我们首先要在系统中源码编译安装cmake工具。
wgethttp://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz tarzxvfcmake-2.8.12.2.tar.gz cdcmake-2.8.12.2 ./configure make&&makeinstall
使用cmake来编译安装MysqL5.6.17
wgethttp://dev.MysqL.com/get/Downloads/mysql-5.6/mysql-5.6.17.tar.gz tarzxvfmysql-5.6.17.tar.gz cdmysql-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&&makeinstall
修改/usr/local/MysqL权限
chmod+w/usr/local/MysqL chown-RMysqL:MysqL/usr/local/MysqL
关于my.cnf配置文件:
在启动MysqL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf” 就是安装目录下 /usr/local/MysqL/my.cnf,这是新版MysqL的配置文件的默认位置! 注意:在CentOS 6.x版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字。 如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MysqL的正确配置,造成无法启动。 由于我们已经卸载了最小安装完成后的mysq库所以,就没必要操作了。
进入support-files目录
cdsupport-files/ 如果还有my.cnf请备份 mv/etc/my.cnf/etc/my.cnf.bak 如果愿意也可以复制配置文件到etc下 cpmy-default.cnf/etc/my.cnf
执行初始化配置脚本,创建系统自带的数据库和表,注意配置文件的路径
/usr/local/MysqL/scripts/MysqL_install_db--defaults-file=/etc/my.cnf--basedir=/usr/local/MysqL--datadir=/usr/local/MysqL/data--user=MysqL
拷贝MysqL安装目录下support-files服务脚本到init.d目录
#拷贝脚本 cpsupport-files/MysqL.server/etc/init.d/MysqLd #赋予权限 chmod+x/etc/init.d/MysqLd
设置开机启动
chkconfigMysqLdon 启动MysqL serviceMysqLdstart 或者 /etc/init.d/MysqLstart
MysqL5.6.x启动成功后,root默认没有密码,我们需要设置root密码。 设置之前,我们需要先设置PATH,要不,不能直接调用MysqL
修改/etc/profile文件 vi/etc/profile 在文件末尾添加 PATH=/usr/local/MysqL/bin:$PATH exportPATH
让配置立即生效
source/etc/profile
登陆测试,默认是没有密码,直接回车就可进入
MysqL-uroot-p
设置MysqL密码
/usr/local/MysqL/bin/MysqLadmin-uroot-ppassword'你的密码'
登陆进命令行模式
查看用户selectuser,hostfromMysqL.user;删除不必要的用户
dropuser""@localhost; dropuser""@c65mini.localdomain; dropuserroot@c65mini.localdomain; dropuserroot@'::1';赋予账号远程访问的权限
GRANTALLPRIVILEGESON*.*TO'root'@'127.0.0.1'IDENTIFIEDBY'你的密码'WITHGRANTOPTION; GRANTALLPRIVILEGESON*.*TO'root'@'localhost'IDENTIFIEDBY'你的密码'WITHGRANTOPTION; GRANTALLPRIVILEGESON*.*TO'root'@'c65mini.localdomain'IDENTIFIEDBY'你的密码'WITHGRANTOPTION;关于删除MysqL的默认root用户参考:http://blog.chinaunix.net/uid-16844903-id-3377690.html
其它一些信息查询: 检查MysqL版本
MysqL-uroot-p"密码"-e"selectversion();"验证MysqL安装路径
ls-ld/usr/local/MysqL/安装PHP5.5.12
这里我安装的是PHP7.1
安装依赖关系
libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。 错误提示:configure: error: Please reinstall the iconv library.
wgethttp://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tarzxvflibiconv-1.14.tar.gz cdlibiconv-1.14 ./configure--prefix=/usr/local/libiconv make&&makeinstall cd..libmcrypt是加密算法扩展库。 错误提示:configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.
wgethttp://iweb.dl.sourceforge.net/project/mcrypt/libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz tarzxvflibmcrypt-2.5.8.tar.gz cdlibmcrypt-2.5.8 ./configure make&&makeinstall cd..Mhash是基于离散数学原理的不可逆向的PHP加密方式扩展库,其在默认情况下不开启。 mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存 错误提示:configure: error: “You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/”
wgethttp://hiveLocity.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2 tarjxvfmhash-0.9.9.9.tar.bz2 cdmhash-0.9.9.9 ./configure make&&makeinstall cd..mcrypt 是 PHP 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。
wgethttp://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz tarzxvfmcrypt-2.6.8.tar.gz cdmcrypt-2.6.8 ./configure make&&makeinstall cd..编译mcrypt可能会报错:configure: error: *** libmcrypt was not found
vi/etc/ld.so.conf 最后一行添加 /usr/local/lib/ 载入 ldconfig编译mcrypt可能会报错:/bin/rm: cannot remove `libtoolT': No such file or directory
修改configure文件,把RM='$RM'改为RM='$RM-f'这里的$RM后面一定有一个空格。如果后面没有空格,直接连接减号,就依然会报错。正式开始编译PHP!
我安装的是PHP7.1
wgethttp://mirrors.sohu.com/PHP/PHP-7.1.1.tar.gz tarzxvfPHP-7.1.1.tar.gz cdPHP-7.1.1 ./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&&makeinstall修改fpm配置PHP-fpm.conf.default文件名称
mv/usr/local/PHP/etc/PHP-fpm.conf.default/usr/local/PHP/etc/PHP-fpm.conf复制PHP.ini配置文件
cpPHP.ini-production/usr/local/PHP/etc/PHP.ini复制PHP-fpm启动脚本到init.d
cpsapi/fpm/init.d.PHP-fpm/etc/init.d/PHP-fpm赋予执行权限
chmod+x/etc/init.d/PHP-fpm添加为启动项
chkconfig--addPHP-fpmchkconfigPHP-fpmon
按照标准,给PHP-fpm创建一个指定的用户和组
创建群组 groupaddwww 创建一个用户,不允许登陆和不创主目录 useradd-s/sbin/nologin-gwww-Mwww
立即启动PHP-fpm
servicePHP-fpmstart #或者 /etc/init.d/PHP-fpmstart
回到/usr/local/src/目录
安装Nginx1.7
Nginx所需的依赖关系,一般我们都需要先装pcre,zlib,前者为了重写rewrite,后者为了gzip压缩。如果系统已经yum 安装了这些库也没关系,无需卸载。直接编译安装最新的就可以了。为了一次性完成编译,先准备编译下面的依赖关系!
1.安装PCRE库
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz tar-zxvfpcre-8.35.tar.gz cdpcre-8.35 ./configure make&&makeinstall
2.安装zlib库
wgethttp://zlib.net/zlib-1.2.8.tar.gz tar-zxvfzlib-1.2.8.tar.gz cdzlib-1.2.8 ./configure make&&makeinstall
3.安装ssl
自由选择是否需要编译 wgethttp://www.openssl.org/source/openssl-1.0.1g.tar.gz tar-zxvfopenssl-1.0.1g.tar.gz
4.安装ngx_pagespeed库 ngx_pagespeed 是一个 Nginx 的扩展模块,可以加速你的网站,减少页面加载时间,它会自动将一些提升web性能的实践应用到网页和相关的资源(CSS、JS和图片)上,无需你修改内容和流程。
按照Google的说法,ngx_pagespeed模块已经被一些客户用于生产环境之中了,包括CDN提供商MaxCDN,按照它的报告该模块使得“页面平均加载时间降低了1.57秒、跳出率降低了1%并且退出百分比下降了2.5%”。wordpress主机服务商ZippyKid说,在使用Nginx的PageSpeed之后,“页面大小降低了75%并且页面的渲染时间提高了50%”。
wgethttps://github.com/pagespeed/ngx_pagespeed/archive/v1.8.31.2-beta.zip unzipv1.8.31.2-beta.zip cdngx_pagespeed-1.8.31.2-beta/ wgethttps://dl.google.com/dl/page-speed/psol/1.8.31.2.tar.gz tar-xzvf1.8.31.2.tar.gz
5、使用google-perftools提供的tcmalloc工具优化Nginx和MysqL
tcmalloc (google-perftools) 是用于优化C++写的多线程应用,比glibc 2.3的malloc快。这个模块可以用来让MysqL在高并发下内存占用更加稳定.
tcmalloc是google-perftools的其中一个工具,用于优化内存分配的效率和速度,帮助在高并发的情况下很好的控制内存的使用。
在MysqL 和Nginx 性能优化方案中,大多数教程都是使用google-perftools提供的tcmalloc工具,tcmalloc在内存的分配上效率和速度要比malloc高得多。
错误提示:configure: error: No frame pointers and no libunwind. The compilation will fail 是因为你没安装libunwind库就开始编译gperftools了,因此必须先libunwind
wgethttp://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz tarzxvflibunwind-1.1.tar.gz cdlibunwind-1.1 CFLAGS=-fPIC./configure makeCFLAGS=-fPIC makeCFLAGS=-fPICinstall
按照官方的说明,必然选择最新版本。
wgethttps://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.2.tar.gz tarzxvfgperftools-2.2.tar.gz cdgperftools-2.2 ./configure make&&makeinstall
准备工作完成,现在开始安装Nginx!,这里添加了前面准备的库关系,注意路径!
wgethttp://Nginx.org/download/Nginx-1.7.0.tar.gz tarzxvfNginx-1.7.0.tar.gz cdNginx-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..
这里我遇到了问题,openssl-1.0.1g有问题,升高版本之后没问题了,安装的是openssl-1.0.1u
wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1u.tar.gz
6、修改Nginx.conf 配置文件
在server块里面 开启 ngx_pagespeed 模块
pagespeedon;
pagespeedFileCachePath/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{allow127.0.0.1;denyall;}
location/ngx_pagespeed_global_statistics{allow127.0.0.1;denyall;}
location/ngx_pagespeed_message{allow127.0.0.1;denyall;}
location/pagespeed_console{allow127.0.0.1;denyall;}
开启 google_perftools 调优支持
我这里没有开启 调优,因为消耗cpu厉害
#先在tmp创建tcmalloc mkdir/tmp/tcmalloc #赋予权限 chmod0777/tmp/tcmalloc/ #一般我们在pid下面添加 google_perftools_profiles/tmp/tcmalloc; #必须是重启,及时载入配置不会生效,Nginx启动重启脚本下面有。 serviceNginxrestart
验证tcmalloc运行状态,这是仅开启了一个worker_processes的效果
[root@bin2aliyun~]#lsof-n|greptcmalloc Nginx24471www16wREG202,10821485/tmp/tcmalloc/.24471
使用tcmalloc (google-perftools) 可以用来让MysqL在高并发下内存占用更加稳定。
在MysqLd_safe脚本文件开始加入 vi/usr/local/MysqL/bin/MysqLd_safe LD_PRELOAD="/usr/local/lib/libtcmalloc.so" serviceMysqLrestart
使用xcache优化PHP性能。
wgethttp://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz
tarzxvfxcache-3.1.0.tar.gz
cdxcache-3.1.0
/usr/local/PHP/bin/PHPize
./configure--enable-xcache--with-PHP-config=/usr/local/PHP/bin/PHP-config
make&&makeinstall
复制xcache查看器到网站目录
cphtdocs//home/wwwroot/htdocs/xcache-rf
cat>>/usr/local/PHP/etc/PHP.ini<<EOF
[xcache-common]
;注意路径
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"
;运行:echo-n"password"|md5sum|awk'{print$1}'计算出MD5加密过的密码
;替换xcache.admin.pass=的值
[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
安装PHPmyadmin
wgethttp://iweb.dl.sourceforge.net/project/PHPmyadmin/PHPMyAdmin/4.2.2/PHPMyAdmin-4.2.2-all-languages.tar.gz tarzxvfPHPMyAdmin-4.2.2-all-languages.tar.gz mvPHPMyAdmin-4.2.2-all-languagesPHPmyadmin cdPHPMyAdmin mkdirconfig chmodo+rwconfig mvconfig/config.inc.PHPconfig.inc.PHP chmodo-rwconfig.inc.PHP rm-rfconfig
Nginx 重启,启动,载入脚本
vi/etc/init.d/Nginx
#!/bin/sh
#
#Nginx-thisscriptstartsandstopstheNginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:Nginx
#config:/etc/Nginx/Nginx.conf
#config:/etc/sysconfig/Nginx
#pidfile:/var/run/Nginx.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0
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]||exit5
[-f$Nginx_CONF_FILE]||exit6
echo-n$"Starting$prog:"
daemon$Nginx-c$Nginx_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}
stop(){
echo-n$"Stopping$prog:"
killproc-p$pidfile$prog
retval=$?
echo
[$retval-eq0]&&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
}
#Upgradethebinarywithnodowntime.
upgrade(){
localoldbin_pidfile="${pidfile}.oldbin"
configtest_q||return6
echo-n$"Upgrading$prog:"
killproc-p$pidfile$prog-USR2
retval=$?
sleep1
if[[-f${oldbin_pidfile}&&-f${pidfile}]];then
killproc-p$oldbin_pidfile$prog-QUIT
success$"$progonlineupgrade"
echo
return0
else
failure$"$progonlineupgrade"
echo
return1
fi
}
#TellNginxtoreopenlogs
reopen_logs(){
configtest_q||return6
echo-n$"Reopening$proglogs:"
killproc-p$pidfile$prog-USR1
retval=$?
echo
return$retval
}
case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest|reopen_logs)
$1
;;
force-reload|upgrade)
rh_status_q||exit7
upgrade
;;
reload)
rh_status_q||exit7
$1
;;
status|status_q)
rh_$1
;;
condrestart|try-restart)
rh_status_q||exit7
restart
;;
*)
echo$"Usage:$0{start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
exit2
esac
注意需要赋予执行的权限:chmod +x /etc/init.d/Nginx
经过优化的Nginx.conf配置文件
userwwwwww;
worker_processes1;
error_log/home/wwwlogs/Nginx_error.logcrit;
pid/usr/local/Nginx/logs/Nginx.pid;
google_perftools_profiles/tmp/tcmalloc;
#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.
worker_rlimit_nofile51200;
events
{
useepoll;
worker_connections51200;
}
http
{
includemime.types;
default_typeapplication/octet-stream;
server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers432k;
client_max_body_size50m;
sendfileon;
tcp_nopushon;
keepalive_timeout60;
tcp_nodelayon;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size256k;
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
gzip_proxiedexpiredno-cacheno-storeprivateauth;
gzip_disable"MSIE[1-6]\.";
#limit_zonecrawler$binary_remote_addr10m;
server_tokensoff;
#logformat
log_formataccess'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for';
server
{
listen80;
server_namewww.cnhzz.com;
indexindex.htmlindex.htmindex.PHP;
root/home/wwwroot/htdocs;
location~\.PHP${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
location/status{
stub_statuson;
access_logoff;
}
location~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires30d;
}
location~.*\.(js|css)?$
{
expires12h;
}
access_log/home/wwwlogs/access.logaccess;
}
includevhost/*.conf;
}
根据需要为虚拟主机增加了ngx_pagespeed google_perftools
log_formatwww.cnhzz.com'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for';
server
{
listen80;
server_namewww.cnhzz.comcnhzz.com;
if($host!='www.cnhzz.com')
{
rewrite^/(.*)$http://www.cnhzz.com/$1permanent;
}
indexindex.PHPindex.htmlindex.htm;
root/home/wwwroot/www.cnhzz.com;
pagespeedon;
pagespeedFileCachePath/var/ngx_pagespeed_cache;
log_formatwww.cnhzz.com'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for';
server
{
listen80;
server_namewww.cnhzz.comcnhzz.com;
if($host!='www.cnhzz.com')
{
rewrite^/(.*)$http://www.cnhzz.com/$1permanent;
}
indexindex.PHPindex.htmlindex.htm;
root/home/wwwroot/www.cnhzz.com;
pagespeedon;
pagespeedFileCachePath/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{allow127.0.0.1;denyall;}
location/ngx_pagespeed_global_statistics{allow127.0.0.1;denyall;}
location/ngx_pagespeed_message{allow127.0.0.1;denyall;}
location/pagespeed_console{allow127.0.0.1;denyall;}
location~\.PHP${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
location~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires30d;
}
location~.*\.(js|css)?$
{
expires12h;
}
access_log/home/wwwlogs/www.cnhzz.com.logwww.cnhzz.com;
}
PHP-fpm优化,注意一个fpm进程大约20M,我这个机器是小内存的云主机,因此开启2个就可以。大内存的话,根据情况换算。
viPHP-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
Nginx配置站点是注意factcgi配置路径是否正确