我使用以下命令在 Lubuntu 13.04 32 位上安装了 nginx:
sudo apt-get install php5-fpm
sudo apt-get install mercurial libpcre3-dev libssl-dev
hg clone -r stable-1.4 http://hg.nginx.org/nginx nginx
cd nginx
auto/configure --with-http_ssl_module
make
sudo make install
之后我禁用了 Apache:
sudo kill $(pidof apache2)
sudo update-rc.d -f apache2 remove
我编辑了 nginx.conf,现在是:
worker_processes 1;
events
{
worker_connections 1024;
}
http
{
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server
{
listen 80;
server_name localhost;
index index.html index.php;
location /
{
root html;
index index.html index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$
{
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root html;
}
}
}
所以我启动了 nginx,我在 html 目录中编写了一个 test.php 脚本,其中只有
<?php
echo 'OK!';
我在浏览器中打开了它,但是不起作用。错误是:
[错误] 2886#0:*1 connect()失败(111:连接被拒绝)连接到上游时,客户端:127.0.0.1,服务器:localhost,请求:“GET /test.php HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“localhost”
php5-fpm 似乎已经启动了,因为如果我尝试 sudo php5-fpm,我会收到此错误:
ERROR: An another FPM instance seems to already listen on /var/run/php5-fpm.sock
答案1
您的 PHP-FPM 安装设置为使用套接字而不是 TCP。
更改此行:
fastcgi_pass fastcgi_pass 127.0.0.1:9000;
到:fastcgi_pass unix:/var/run/php5-fpm/php5-fpm.sock;
或者,您可以修改 nginx.conf 文件listen =
以使用端口而不是套接字。