系统默认安装
1、apt-get install nginx
2、apt-get install php5 php5-fpm php5-cli php5-cgi php5-gd php5-curl php5-mcrypt
3、配置nginx
fpm:
4、location ~ .php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
5、nginx 错误 connect() to unix:/var/run/php5-fpm.sock failed
A、可能不存在php5-fpm.sock
/etc/php5/fpm/pool.d/www.conf
里面找到这样一段代码:
listen = 127.0.0.1:9000
在这上面代码的下面添加一行:
listen = /var/run/php5-fpm.sock
保存后启动php5-fpm
/etc/init.d/php5-fpm restart
如果重启php5-fpm就出现502还需要修改
vi /etc/php5/fpm/pool.d/www.conf
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
设置自动启动 nginx 和 php5-fpm
update-rc.d nginx defaults
update-rc.d php5-fpm defaults
B、chmod 0666 /var/run/php5-fpm.sock
cgi:
sudo vi /etc/php5/fpm/php.ini
设置
cgi.fix_pathinfo=0
vi /etc/nginx/sites-available/default
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
修改 fastcgi 参数,sudo vi /etc/nginx/fastcgi_params
加入:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
重新启动 nginx 和 php-fpm,配置完成:
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm reload
如果出现 502 Bad Gateway 错误的话,需要进行如下操作
sudo vi /etc/php5/fpm/pool.d/www.conf
找到 listen 字段,改成
listen = 127.0.0.1:9000