Chinaunix首页 | 论坛 | 博客
  • 博客访问: 757100
  • 博文数量: 434
  • 博客积分: 11187
  • 博客等级: 上将
  • 技术积分: 5221
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-19 01:00
文章分类

全部博文(434)

文章存档

2016年(2)

2013年(1)

2012年(115)

2011年(195)

2010年(32)

2009年(89)

分类: LINUX

2009-04-02 15:08:35

本文链接:

 安装Nginx 需要 安装编译环境

  yum -y install gcc gcc-c++ kernel-devel

下载nginx.网站不用我提供了,大家都聪明。。^-^ 下面的我的编译参数

./configure  --prefix=/usr/local/nginx --with-http_stub_status_module

安装PHP 安装前准备,我的原则是能不编译就不编译,所以其它php编译的包都使用Centos本身的devel包

yum install -y libtool libmcrypt-devel libxml2-devel flex bison \
pcre-devel zlib-devel openssl-devel gd-devel mysql-devel

然后安装php-fpm的补丁包,为什么要打上见我另外的文章. 先下载php,然后解压,然后给这个补丁打进去

tar zxvf php-5.2.8.tar.gz
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz |patch -d php-5.2.8 -p1
cd php-5.2.8

我的编译参数

./configure --enable-fastcgi --enable-fpm --enable-cli --with-mcrypt --with-zlib \
--enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-gd \
--with-jpeg-dir=/usr/lib64/ --enable-gd-native-ttf --disable-pdo --disable-reflection \
--with-libdir=lib64 --with-xpm-dir=/usr/lib64 --enable-gd-jis-conv \
--with-freetype-dir=/usr/include/freetype2 --enable-shared
make
make install
cp php.ini-recommended /usr/local/php/lib/php.ini

注:我在安装时出错,提示我 /usr/bin/ld: cannot find -lltdl 解决方法

ldconfig -p |grep ltdl
libltdl.so.3 (libc6) ->> /usr/lib64/libltdl.so.3
cd /usr/lib64
ln -s libltdl.so.3.1.4 libltdl.so

安装完后配置php-fpm.

vim /usr/local/php/etc/php-fpm.conf

去掉这二行的注解

<value name="user">nobodyvalue>
<value name="group">nobodyvalue>

有关如何确定PHP-FPM 的Worker 的数量,用 'netstat -np | grep 127.0.0.1:9000' 收集数据。 然后设置php-fpm.conf 中的 max_children 的数值使等待的数先量变为最小。 安装Xcache到php中 先下载最新的xcache解压进入它的目录中

/usr/local/php/bin/phpize --clean
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache
make
make install

记的要根据安装的php的位置来指定,安装会完提示 Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ 记下这个位置.来配置php

vim /usr/local/php/lib/php.ini

加入下面这些内容

[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache]
xcache.shm_scheme = mmap
xcache.size = 32M

好了,到最后了,集成nginx和php一起跑

vim /usr/local/nginx/conf/fastcgi_params

只要加入一行,别的使用默认就行了

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

最后配置你的nginx

vim /usr/local/nginx/conf/nginx.conf
user  nobody;
#运行nginx的用户
worker_processes 2;
#工作的进程,我的内存少
 
events {
use epoll;
worker_connections 768;
}
 
 
http {
include mime.types;
default_type application/octet-stream;
 
sendfile on;
keepalive_timeout 300;
 
gzip on;
gzip_comp_level 1;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
#打开gzip的压缩
 
server {
listen 80;
server_name www.php-oa.com;
index index.php index.html index.html;
root /home/www/public_html/;
#你的主网站的地址
 
location ~ .php$ {
 
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
#指定php的处理方法
}
location / {
index index.php index.html index.htm;
if (-e $request_filename) {
break;
}
rewrite ^/(.+)$ /index.php?q=$1 last;
 
#以上是我的wordpress的url重写
}
 
location /NginxStatus {
stub_status on;
access_log on;
}
 
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
#对gif,jpg之类图象文件设置过期时间,让没有变更的文件不会在次请求
}
 
location ~ .*\.(js|css)?$
{
expires 7d;
#对js和css设置过期时间
}
 
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /var/log/nginx/access.log access;
#日志存放的地方
 
 
}
 
}

 启动

/usr/local/sbin/php-fpm start

/usr/local/nginx/sbin/nginx

FQA:

nginx平滑重启

ps aux| grep nginx找到nginx的进程号

kill -HUP xxxx(进程号)

eg:kill -HUP 1000

nginx alias目录

location /abc/ {
alias /home/html/abc/;
}

阅读(1996) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~