1.sudo apt-get install spawn-fcgi
原先我是安装php-fpm的,结果那个东西搞死就是设置不好,于是废掉,改用spawn-fcgi. 这玩意原先是lighttpd的组件,后来独立了,完全可以单独安装,并且配合nginx使用。
配置nginx和spawn-fcgi:修改/etc/nginx/fastcgi_params,加入下面这一行:
1.sudo apt-get install spawn-fcgi
在/etc/php5/cgi/php.ini中找到cgi.fix_pathinfo=1这一行,把前面的注释去掉。这样php-cgi才能正常使用SCRIPT_FILENAME这个变量
打开/etc/nginx/sites-available/default文件,稍做修改。我把我的贴在这里:
server {
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name localhost;
root /var/www/nginx-default;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www/nginx-default;
index index.php index.html index.html index.htm;
}
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
location /images {
root /usr/share;
autoindex on;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/nginx-default;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#proxy_pass ;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;#####注意这里原先少一个空格!!!
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#deny all;
#}
}