Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。 用Nginx搭建web服务器,比Apache相比,占用更少的资源,支持更多的并发连接,体现更高的效率。

 

yum -y install gcc openssl-devel zlib-devel pcre-devel
 
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel ssse2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
 
nginx的安装

添加用户,用户组

groupadd www
uesradd -g www -s /bin/falsh -M www
 
#安装Nginx tar -zxvf nginx-1.2.0.tar.gz && cd nginx-1.2.0 &&

./configure --user=www --group=www \ --prefix=/usr/local/webserver/nginx \ --sbin-path=/usr/local/webserver/nginx/sbin/nginx \ --conf-path=/usr/local/webserver/nginx/conf/nginx.conf \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-pcre \ --lock-path=/var/run/nginx.lock \ --pid-path=/var/run/nginx.pid  

第三步:更改配置

 
#更改配置 vi /usr/local/webserver/nginx/conf/nginx.conf  #修改一些参数,别直接替换文件,这只是一部分 user www  events {     use epoll;     worker_connections  1024; } listen       80;
server_name localhost;
index     
index.php index.html index.htm ;
root     /www/html;
location ~ .*\.(php|php5)?$
{ fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /www/html/$fastcgi_script_name; include fastcgi_params;
            include        fastcgi.conf;
} #检测配置文件 /usr/local/webserver/nginx/sbin/nginx - t #提示表示成功 #nginx: the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok #nginx: configuration file /usr/local/webserver/nginx/conf/nginx.conf test is successful
编译结束后如果没出错的话,make && make install 安装。 安装结束后启动nginx,/usr/local/webserver/nginx/sbin/nginx,然后用netstat -tunpl | grep:80查看端口是否启动。 关闭防火墙,在浏览器里输入192.168.127.6(当前实验主机),看到welcome to nginx!则表示nginx安装成功。 接下来安装mysql,这跟搭建lamp环境时完全一样,下面就不加以说明。 安装PHP:

安装libiconv和libevent
tar -zxvf libevent-1.4.12-stable,tar zxf libiconv-1.14.tar.gz
分别解压,配置安装
./configure    && make && make install

php
 
编译,安装
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --with-libevent-dir=/usr/local --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr/local
 
make ZEND_EXTRA_LIBS='-liconv'
make && make install

设置php支持
nginx.conf
 43          location / {
 44              root   html;
 45              index index.php index.html index.htm;

 

 

mv /usr/loca/php/etc/php-fpm-default.conf php-fpm.conf
修改 php-fpm.conf
131 pm.max_children = 50
136 pm.start_servers = 20
141 pm.min_spare_servers = 5
146 pm.max_spare_servers = 35
152 pm.max_requests = 500
执行 ./usr/local/php/sbin/php-fpm
 
编写 phpinfo 测试
vim /www/html/index.php
<?
Phpinfo();
?>