linux安装nginx和php-fastcgi
16 / 01 / 2015 buling

      之前发过lamp安装过程,地址:LAMP安装配置入门。之前也试图把这个站点改为nginx+fastcgi,但之前尝试了一次,没有搞定,修改中站点不能访问,主要是会影响实时公交的查询用户。昨天在22买了一台云主机,香港的。刚开始选择安装的是centos7.0,但安装完成后,发现本地可以访问,外网不行,很自然是防火墙,但iptables的initshell没有,这我就抓狂了,半天没搞定,最后重装为centos6.5纯净版。安装nginx就不赘述了,很简单
先给一篇整个安装过程的好文章:Install Nginx, PHP 5.5 and FastCGI on CentOS 6

安装php-fpm

yum install php-fpm 这我就不说了

配置php-fpm

//找到php-fpm的配置目录下的www.conf。默认为:/etc/php-fpm.d/www.conf
//监听端口也在该配置中
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

启动fastcgi: /etc/init.d/php-fpm start

配置nginx

当nginx收到php的请求时需要转交给fastcgi处理,配置如下:

server {
    listen      80;
    server_name www.mjix.com;
    server_name_in_redirect  off;
    root  /home/www/public_html/www.mjix.com/html;
    index index.html index.php;
    error_log  /var/log/nginx/mjix_error.log;
    access_log /var/log/nginx/mjix_access.log main;
    location ~* \.(htm|html|xml|shtml)$ {
        expires 600;
    }
    location ~* \.(htc|js|gif|ico|png|swf|css|jpg|jpeg)$ {
        expires 365d;
    }
    ssi on; #这里是开启ssi,关于ssi自行google
    ssi_silent_errors on;
    #下面这句是加载重写脚本,由于nginx不支持.htacess
    include /home/www/public_html/www.mjix.com/html/.xxx.conf;
    #发现是php请求,转交给9000端口处理
    location ~* \.php$ {
         fastcgi_pass  127.0.0.1:9000;
         fastcgi_index index.php;
         #这句是把nginx请求变量转交fastcgi,这样fastcgi才知道执行的php文件路径
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }
}

在配置多站点时遇到 “nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32”错误,解决办法,在nginx的配置文件nginx.conf中的http中加入如下语句:

server_names_hash_bucket_size 64;

解释在这里:nginx could not build the server_names_hash 解决方法
刚开始忘记配置 fastcgi_param这句,请求总是无法转到fastcgi,坑大了

无标签信息
0