nginx(五)nginx与php的安装配置
经过前面学习,对nginx有个大概的了解,来配置LNMP;只要是在系统安装过程中选择安装比较齐全的包,基本上系统都能满足安装要求,下面是我一个一个测试的,基本上全部安装所需的库文件,放心安装;# rpm -qa |grep zlib
zlib-devel-1.2.3-3
zlib-1.2.3-3
# rpm -qa |grep openssl
openssl-0.9.8e-12.el5
openssl-devel-0.9.8e-12.el5
# rpm -qa |grep pcre
pcre-6.6-2.el5_1.7
pcre-devel-6.6-2.el5_1.7
# rpm -qa |grep gcc
compat-libgcc-296-2.96-138
compat-gcc-34-g77-3.4.6-4
gcc-c++-4.1.2-46.el5
libgcc-4.1.2-46.el5
compat-gcc-34-3.4.6-4
compat-gcc-34-c++-3.4.6-4
gcc-java-4.1.2-46.el5
gcc-4.1.2-46.el5
gccp-gfortran-4.1.2-46.el5
# rpm -qa |grep autoconf
autoconf-2.59-12
# rpm -qa |grep automake
automake-1.9.6-2.1
automake16-1.6.3-8
automake15-1.5-16
automake17-1.7.9-7
automake14-1.4p6-13
# rpm -qa |grep libjpeg
libjpeg-devel-6b-37
libjpeg-6b-37
# rpm -qa |grep libpng
libpng-1.2.10-7.1.el5_3.2
libpng-devel-1.2.10-7.1.el5_3.2
# rpm -qa |grep freetype
freetype-2.2.1-21.el5_3
freetype-devel-2.2.1-21.el5_3
# rpm -qa |grep libxml2
libxml2-python-2.6.26-2.1.2.8
libxml2-2.6.26-2.1.2.8
libxml2-devel-2.6.26-2.1.2.8
# rpm -qa |grep glibc
glibc-2.5-42
glibc-devel-2.5-42
compat-glibc-2.3.4-2.26
glibc-common-2.5-42
compat-glibc-headers-2.3.4-2.26
glibc-headers-2.5-42
# rpm -qa |grep glib2
glib2-2.12.3-4.el5_3.1
glib2-devel-2.12.3-4.el5_3.1
# rpm -qa |grep bzip2
bzip2-devel-1.0.3-4.el5_2
bzip2-libs-1.0.3-4.el5_2
bzip2-1.0.3-4.el5_2
# rpm -qa |grep ncurses
ncurses-devel-5.5-24.20060715
ncurses-5.5-24.20060715
# rpm -qa |grep curl
curl-devel-7.15.5-2.1.el5_3.5
curl-7.15.5-2.1.el5_3.5
# rpm -qa |grep e2fsprogs
e2fsprogs-libs-1.39-23.el5
e2fsprogs-1.39-23.el5
e2fsprogs-devel-1.39-23.el5
# rpm -qa |grep krb5
pam_krb5-2.2.14-10
krb5-auth-dialog-0.7-1
krb5-libs-1.6.1-36.el5
krb5-workstation-1.6.1-36.el5
krb5-devel-1.6.1-36.el5
# rpm -qa |grep libidn
libidn-0.6.5-1.1
libidn-devel-0.6.5-1.1
# rpm -qa |grep nss_ldap
nss_ldap-253-21.el5
openldap 这个库缺少
#yum install openldap*
# rpm -qa |grep openldap
openldap-clients-2.3.43-3.el5
openldap-2.3.43-3.el5
openldap-devel-2.3.43-3.el5
openldap-servers-2.3.43-3.el5
openldap-servers-sql-2.3.43-3.el5
openldap-servers-overlays-2.3.43-3.el5
1、安装LNMP 所需的安装包有点多,要耐心.......,下载的链接张老师的博客上有:
http://sysoev.ru/nginx/nginx-0.8.46.tar.gz
#nginx主程序包
http://www.php.net/get/php-5.2.14.tar.gz/from/this/mirror
#PHP主程序包
http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
#PHP的FastCGI进程管理补丁包
http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/
#mysql主程序包
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
libiconv库是一个基于GNU协议的开源库,主要是解决多语言编码处理转换等应用问题;
由于历史原因,国际化的文字常常由于语言或者国家的原因使用不同的编码。随着互联网时代的到来,通过互联网进行文字交流也逐渐增多:浏览外国的网站,这个时候字符编码的转换变得尤为重要。这带来了一个问题,就是许多字符在某一种编码方式中没有。为了解决这种混乱,Unicode的编码方式被建立。 Unicode是一种超级编码包含了所有这些编码的字符集,因此一些新的文本格式像XML的默认编码方式就是Unicode.
但是很多老式的计算机还在使用当地的传统的字符编码方式。而一些程序,例如邮件程序和浏览器必须能在这些不同的用户编码之间作转换。其他的一些程序则内置支持Unicode,以顺利支持国际化的处理,但是仍然有在Unicode和其他的传统编码之间转换的需求。GNU的libiconv就是为这两种应用设计的编码转换库。libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。
http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0
#安全线程加密库主程序包
http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0
#Mcrypt是一个功能强大的加密算法扩展库,它包括有22种算法
http://pecl.php.net/get/memcache-2.2.5.tgz
#memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,最初为了加速 LiveJournal 访问速度而开发的,后来被很多大型的网站采用。目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。起初作者编写它可能是为了提高动态网页应用,为了减轻数据库检索的压力,来做的这个缓存系统。它的缓存是一种分布式的,也就是可以允许不同主机上的多个用户同时访问这个缓存系统, 这种方法不仅解决了共享内存只能是单机的弊端,同时也解决了数据库检索的压力,最大的优点是提高了访问获取数据的速度!基于memcache作者对分布式 cache的理解和解决方案。 memcache完全可以用到其他地方 比如分布式数据库, 分布式计算等领域。
http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0
#Mhash扩展库,Mhash扩展库支持12种混编算法
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
#正则表达式扩展主程序包
http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。使您的PHP程序代码执效率能提高1-10倍;
http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
#PDO 是 PHP 数据对象的缩写, 是一种访问数据库的更便捷、安全的途径。通过该方式,数据库开发者可以更方便地写出移植性较高的代码。PDO 并不是类似于 PearDB 的数据库抽象层,而 更像一种采用了统一 API (应用编程接口)的数据访问层。
如何启用PDO?要启用 PDO 配置,须打开 pdo 、pdo_sqlite、pdo_mysql等所的扩展模块
http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
#是一个免费的创建、编辑、合成图片的软件。它可以读取、转换、写入多种格式的图片。图片切割、颜色替换、各种效果的应用,图片的旋转、组合,文本,直线,多边形,椭圆,曲线,附加到图片伸展旋转。ImageMagick是免费软件:全部源码开放,可以自由使用,复制,修改,发布。它遵守GPL许可协议。它可以运行于大多数的操作系统。ImageMagick的大多数功能的使用都来源于命令行工具。通常来说,它可以支持以下程序语言: Perl, C, C++, Python, PHP, Ruby, Java
http://pecl.php.net/get/imagick-2.3.0.tgz
#一般用php处理图片都是使用GD库或者GD2的函数库,一般编译php环境都会搭上GD库,大多数开源程序也是用GD来处理图片的,但是它只能现实诸如调整大小、增加水印等基础功能,要想用GD来做复杂图形是非常困难的。
基于命令行的图像处理软件ImageMagick,能实现非常丰富的功能。如果服务器上安装了ImageMagick,php脚本可以使用 shell命令来完成,也可以用php的原生函数库Imagick或者MagickWandForPHP函数来调用ImageMagick软件来实现。
因为Linux系统下PHP往往没有执行shell的权限,直接用shell来操作ImageMagick不太可能,综合考虑,Imagick函数库连接到ImageMagick软件比较好,而且是面向对象方式的。
2、安装php(fastcgi模式)
(1)、安装php所需的支持库
# tar -zxvf libiconv-1.13.1.tar.gz -C ../install_packet/
# ./configure --prefix=/usr/local
# make
# make install
# tar -zxvf libmcrypt-2.5.8.tar.gz -C ../install_packet/
# ./configure
# make
# make install
# /sbin/ldconfig (配置动态连接器(ld)运行时邦定)
# cd libltdl/
# ./configure --enable-ltdl-install
# make
# make install
# tar -zxvf mhash-0.9.9.9.tar.gz -C ../install_packet/
# cd mhash-0.9.9.9/
# ./configure
# make
# make install
# ln -s /usr/local/lib/* /usr/lib
(这一步不用做了 ,做完成上面步骤后/usr/lib下面已经存在了)
# ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
# ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
# ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
# ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
# ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
# ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
# ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
# ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
# ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
# ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
# tar -zxvf mcrypt-2.6.8.tar.gz -C ../install_packet/
# /sbin/ldconfig
# ./configure
# make
# make install
(2)、安装mysql
# groupadd mysql
# useradd -g mysql mysql
#tar -zxvf mysql-5.5.3-m3.tar.gz -C ../install_packet/
# ./configure --prefix=/usr/local/mysql --enable-assembler --with- --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
# make
# make install
# cp support-files/my-large.cnf /etc/my.cnf
# pwd
/usr/local/mysql
# bin/mysql_install_db --user=mysql
Installing MySQL system tables...
100903 13:30:41 /usr/local/mysql/libexec/mysqld: unknown variable 'thread_concurren cy=8'
100903 13:30:41 Aborting
100903 13:30:41 /usr/local/mysql/libexec/mysqld: Shutdown complete
.......
mysql 初始化报错,发现网上有哥们已经解决了这个问题,实在是强大,原因是my.cnf中有一行:
thread_concurrency = 8
thread_concurrency这个变量,意思是并发的线程数,并且根据给的解释是该参数取值为服务器逻辑CPU数量×2,而如果每颗物理CPU又支持H.T超线程,所以实际取值为4 × 2 = 8。而我这个机器是ADM闪龙3000 单核的CPU,并不符合它的要求,所以它提示“unknown variable ‘thread_concurrency=8′”是个未知变量。对my.cnf做一些修改,把’thread_concurrency=8′注释掉
重新初始化OK
# bin/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
...........
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .
# cp share/mysql/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# cd /etc/init.d/
# chmod +x mysqld
# chkconfig --list mysqld
mysqld 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
# service mysqld start
Starting MySQL [确定]
# cp /usr/local/mysql/bin/* /sbin/
# mysql
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.3-m3-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit
Bye
# mysqladmin -u root -h localhost password 'mysql'
# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
#
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.3-m3-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
(3)、编译安装pHP (fastcgi模式)
# tar -zxvf php-5.2.14.tar.gz -C ../install_packet/
# pwd
/home/install_packet/php-5.2.14
# gzip -cd php-5.2.14-fpm-0.5.14.diff.gz |patch -d php-5.2.14 -p1
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash -enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
# make ZEND_EXTRA_LIBS='-liconv'
# make install
# cp php.ini-dist /usr/local/php/etc/php.ini
(4)、安装PHP扩展
# tar -zxvf memcache-2.2.5.tgz -C ../install_packet/
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
# tar -jxvf eaccelerator-0.9.6.1.tar.bz2 -C ../install_packet/
# cd eaccelerator-0.9.6.1/
# /usr/local/php/bin/phpize
# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
# make
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
# tar -zxvf PDO_MYSQL-1.0.2.tgz -C ../install_packet/
# cd PDO_MYSQL-1.0.2/
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-
mysql=/usr/local/mysql
# make
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613
# tar -zxvf ImageMagick.tar.gz -C ../install_packet/
# ./configure
# make
# make install
# tar -zxvf imagick-2.3.0.tgz -C ../install_packet/
# cd imagick-2.3.0/
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make
# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
(5)、修改php.ini文件
找到491行的extension_dir = "./"
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613" 指定模块所在的位置;
在这行后面加上
493extension = "imagick.so"
494extension = " memcache.so"
495extension = "pdo_mysql.so"
在 101行处
修改 output_buffering = Off为 output_buffering = On
把523 处的注释去掉, cgi.fix_pathinfo=0 防止nginx文件类型错误解析漏洞
6、配置php加速eaccelerator
创建缓存文件夹;
# mkdir eaccelerator_cache
在php.ini配置文件末尾加上如下:
1290
1291 extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so
1292 eaccelerator.shm_size="32"
1293 eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
1294 eaccelerator.enable="1"
1295 eaccelerator.optimizer="1"
1296 eaccelerator.check_mtime="1"
1297 eaccelerator.debug="0"
1298 eaccelerator.filter=""
1299 eaccelerator.shm_max="0"
1300 eaccelerator.shm_ttl="3600"
1301 eaccelerator.shm_prune_period="360"
1302 eaccelerator.shm_only="0"
1303 eaccelerator.compress="1"
1304 eaccelerator.compress_level="9"
(7)、悲剧了,空余的机器被拿去用了,只好换个机器,创建www 用户和组,及两个虚拟主机域名目录www.nginx.com与web.nginx.com
# groupadd www
# useradd -g www www
# mkdir -p /web/htdocs/www.nginx.com
# chown -R www:www /web/htdocs/www.nginx.com
# mkdir -p /web/htdocs/web.nginx.com
# chown -R www:www /web/htdocs/web.nginx.com/
8、修改php-fpm配置文件,黄色标记的是修改值
1
2
3
4 All> 5
6
7
8 Pid file
9 /usr/local/php/logs/php-fpm.pid
10
11 Error log file
12 /usr/local/php/logs/php-fpm.log
13
14 Log level
15 notice
16
17 When this amount of php processes exited with SIGSEGV or SIGBUS ...
18 10
19
20 ... in a less than this interval of time, a graceful restart will be initiated.
21 Useful to work around accidental curruptions in accelerator's shared memory.
22 1m
23
24 Time limit on waiting child's reaction on signals from master
25 5s
26
27 Set to 'no' to debug fpm
28 yes
29
30
31
32
33
34
35
36 Name of pool. Used in logs and stats.
37 default
38
39 Address to accept fastcgi requests on.
40 Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
41 127.0.0.1:9000
42
43
44
45 Set listen(2) backlog
46 -1
47
48 Set permissions for unix socket, if one used.
49 In Linux read/write permissions must be set in order to allow connections from web server.
50 Many BSD-derrived systems allow connections regardless of permissions.
51
52
53 0666
54
55
56 Additional php.ini defines, specific to this pool of workers.
57
58
59
60
61
62 Unix user of processes
63
64
65 Unix group of processes
66
67
68 Process manager settings
69
70
71 Sets style of controling worker process count.
72 Valid values are 'static' and 'apache-like'
73 static
74
75 Sets the limit on the number of simultaneous requests that will be served.
76 Equivalent to Apache MaxClients directive.
77 Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
78 Used with any pm_style.
79 64(如果机器内存小于3G,可以设置64个进程)
80
81 Settings group for 'apache-like' pm style
82
83
84 Sets the number of server processes created on startup.
85 Used only when 'apache-like' pm_style is selected
86 20
87
88 Sets the desired minimum number of> 89 Used only when 'apache-like' pm_style is selected
90 5
91
92 Sets the desired maximum number of> 93 Used only when 'apache-like' pm_style is selected
94 35
95
96
97
98
99
100 The timeout (in seconds) for serving a single request after which the worker process will be terminated
101 Should be used when 'max_execution_time' ini option does not stop script execution for some reason
102 '0s' means 'off'
103 0s
104
105 The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
106 '0s' means 'off'
107 0s
108
109 The log file for slow requests
110 logs/slow.log
111
112 Set open file desc rlimit
113 65535
114
115 Set max core> 116 0
117
118 Chroot to this directory at the start, absolute path
119
120
121 Chdir to this directory at the start, absolute path
122
123
124 Redirect workers' stdout and stderr into main error log.
125 If not set, they will be redirected to /dev/null, according to FastCGI specs
126 yes
127
128 How much requests each process should execute before respawn.
129 Useful to work around memory leaks in 3rd party libraries.
130 For endless request processing please specify 0
131 Equivalent to PHP_FCGI_MAX_REQUESTS
132 500
133
134 Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
135 Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
136 Makes sense only with AF_INET listening socket.
137 127.0.0.1
138
139 Pass environment variables like LD_LIBRARY_PATH
140 All $VARIABLEs are taken from current environment
141
142 $HOSTNAME
143 /usr/local/bin:/usr/bin:/bin
144 /tmp
145 /tmp
146 /tmp
147 $OSTYPE
148 $MACHTYPE
149 2
150
151
152
153
154
155
156
(9)、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为64
把配置文件的63行和66行修改如下:
62 Unix user of processes
63 www
64
65 Unix group of processes
66 www
切记要把63行和66行的注释符号去掉不然在启动时会出错的!
fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool 'default'
# /usr/local/php/sbin/php-fpm start
Starting php_fpm . done
# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 2630/hpiod
tcp 0 0 0.0.0.0:833 0.0.0.0:* LISTEN 2347/rpc.statd
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 5285/php-cgi
........
3、安装nginx
(1)、安装nginx及所需要的pcre库
# ./configure
# make
# make install
# cd nginx-0.8.48/
# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#make
#make install
(2)、创建nginx的日志文件
# mkdir -p web/nginxlogs
# chmod +w web/nginxlogs/
# chown -R www:www web/nginxlogs/
(3)、修改nginx的配置文件如下:
1
2 user www www;
3 worker_processes1;
4 error_log /web/nginxlogs/error.logcrit;
5 pid /usr/local/nginx/nginx.pid;
6 worker_rlimit_nofile 65535;
7 events {
8 use epoll;
9 worker_connections1024;
10 }
11
12
13 http {
14 include mime.types;
15 default_typeapplication/octet-stream;
16
17 server_names_hash_bucket_size 128;
18 client_header_buffer_size 32k;
19 large_client_header_buffers 4 32k;
20 client_max_body_size 8m;
21
22
23 sendfile on;
24 tcp_nopush on;
25
26 #keepalive_timeout0;
27 keepalive_timeout60;
28 tcp_nodelay on;
29
30 fastcgi_connect_timeout 300;
31 fastcgi_send_timeout 300;
32 fastcgi_read_timeout 300;
33 fastcgi_buffer_size 64k;
34 fastcgi_buffers 4 64k;
35 fastcgi_busy_buffers_size 128k;
36 fastcgi_temp_file_write_size 128k;
37
38 gzipon;
39 gzip_min_length 1k;
40 gzip_buffers 4 16k;
41 gzip_http_version 1.0;
42 gzip_comp_level2;
43 gzip_typestext/plain application/x-javascript text/css application/xml;
44 gzip_vary on;
45
46 server {
47 listen 80;
48 server_namewww.nginx.com;
49 root /web/htdocs/www.nginx.com;
50 indexindex.html index.htm index.php;
51
52 location ~.*\.(php|php5)?$ {
53 fastcgi_pass 127.0.0.1:9000;
54 fastcgi_indexindex.php;
55 include fastcgi.conf;
56 }
57
58 location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$
59 {
60 expires 30d;
61 }
62 location ~.*\.(js|css)$
63 {
64 expires 1h;
65 }
66 log_formatwwwaccess'$remote_addr - $remote_user [$time_local] "$request" '
67 '$status $body_bytes_sent "$http_referer" '
68 '"$http_user_agent" $http_x_forwarded_for';
69 access_log/web/nginxlogs/wwwaccess.logwwwaccess;
70 }
71
72
73 server {
74 listen 80;
75 server_nameweb.nginx.com;
76 root /web/htdocs/web.nginx.com;
77 indexindex.html index.htm index.php;
78 location ~.*\.(php|php5)?$
79 {
80 fastcgi_pass 127.0.0.1:9000;
81 fastcgi_indexindex.php;
82 include fastcgi.conf;
83 }
84 log_formatwebaccess'$remote_addr - $remote_user [$time_local] "$request"'
85 '$status $body_bytes_sent "$http_referer"'
86 '"$http_user_agent" $http_x_forwarded_for';
87 access_log/web/nginxlogs/webaccess.logwebaccess;
88 }
89 }
(4)、保持conf/下fastcgi.conf配置文件不变就可以了
(5)、启动nginx
#/usr/
# /usr/local/nginx/sbin/nginx
(6)、开机启动nginx 与php
# vi /etc/rc.local
ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
(7)修改文件中先检查配置文件是否正确,然后在启动
# /usr/local/nginx/sbin/nginx -t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
# kill -HUP `cat /usr/local/nginx/nginx.pid`
或者
# /usr/loca/nginx/sbin/nginx -s> 4、测试
在www.nginx.com的文档目录中
# vi index.php/
类似的在web.nginx.com中新建一个index.php文件:
基本上算是完成了涨老师的实验配置
页:
[1]