CodeIgniter + php-fpm + nginx 出现502

归去

今天要把CodeIgniter部署在CentOS(VPS)上,也就是这篇博客所在的机器,原来的Wordpress是直接一键安装的,再部署一个CodeIgniter估计要费一番周折了。不过事实证明这并没有花太多的时间。将CodeIgniter下载下来,解压到/home/wwwroot/contact/目录下,修改nginx配置文件,出现502和403,折腾了三四个小时的样子,总算搞定了,最后的结果就是这样的:

nginx中的配置如下

server { listen 80; server_name todo.witcher42.me; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/contact;

location ~\* \\.php$ {
    fastcgi\_pass 127.0.0.1:9000;
    fastcgi\_index index.php;
    include fastcgi\_params;
    #fastcgi\_split\_path\_info ^(.+\\.php)(.\*)$;
    fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;
}

}

起先,php-fpm的配置(我的路径是/usr/local/php/etc/php-fpm.conf)中有这样一句

/tmp/php-cgi.sock

这句话的意思是说,使用unix的sock通信,sock文件的地址就是上边的/tmp/php-cgi.sock,这个原本是因为Wordpress的缘故而自动生成的,公司的配置和网上的介绍离都给出了使用ip:port的各式,我尝试了一下,果然是OK了,修改成这样:

127.0.0.1:9000