安装nginx1.8.0最新稳定版:
1. cd /usr/src 2. wget http://nginx.org/download/nginx-1.8.0.tar.gz 1.8.0为最新stable版本 3. tar -xvf nginx-1.8.0.tar.gz 4. cd nginx-1.8.0 5. /usr/local/nginx 6../configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --with-http_stub_status_module
安装php的php-fpm只需要在执行configure脚本的时候加入–enable-fpm,最后把php-fpm.conf.default配置拷贝到php的etc配置目录下,并取消daemoize=yes的注释
php-fpm的启动/停止/重启脚本,php官方已经写好了,只需要拷贝php源码安装目录/sapi/fpm/init.d.php-fpm到/etc/init.d下面,不要忘记给予x权限。
配置nginx以php-fpm处理php脚本:
server{
listen 80;
server_name www.xxx.com;
access_log logs/xxx.access.log;
location /{
index index.html index.php;
root /var/www/xxx/;
#try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
root /var/www/xxx/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
一般配置出问题的都是fastcgi_param这里,当nginx把脚本文件名传给php-fpm的时候,要注意路径,否则很容易造成php在错误的目录中找脚本文件。好吧,我就在这里被坑了很久
