我有一个在 www.myapp.com 上运行的 rails 应用程序(我们称之为 myapp)。我想在 www.myapp.com/blog 添加一个 wordpress 博客。rails 应用程序的 Web 服务器很薄(请参阅上游块)。wordpress 使用 php-fastcgi 运行。
rails 应用程序运行良好。我的问题如下:/home/myapp/myapp/log/error.log error
我得到:
2013/06/24 10:19:40 [error] 26066#0: *4 connect() failed (111: Connection refused) while connecti\
ng to upstream, client: xx.xx.138.20, server: www.myapp.com, request: "GET /blog/ HTTP/1.1", \
upstream: "fastcgi://127.0.0.1:9000", host: "www.myapp.com"
这是 nginx conf 文件:
upstream myapp {
server unix:/tmp/thin_myapp.0.sock;
server unix:/tmp/thin_myapp.1.sock;
server unix:/tmp/thin_myapp2.sock;
}
server {
listen 80;
server_name www.myapp.com;
client_max_body_size 20M;
access_log /home/myapp/myapp/log/access.log;
error_log /home/myapp/myapp/log/error.log error;
root /home/myapp/myapp/public;
index index.html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# Index HTML Files
if (-f $document_root/cache/$uri/index.html) {
rewrite (.*) /cache/$1/index.html break;
}
if (!-f $request_filename) {
proxy_pass http://myapp;
break;
}
# try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
}
location /blog/ {
root /var/www/wordpress;
fastcgi_index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /blog/index.php?q=$1 last;
}
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/wordpress$fastcgi_script_name;
fastcgi_pass localhost:9000; # port to FastCGI
}
}
知道为什么这不起作用吗?如何确保 php-factcgi 配置正确?
编辑: 我无法测试 fastcgi 是否正在使用 telnet 运行:
$> telnet 127.0.0.1 9000
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
但事实并非如此。
答案1
php-fpm 未运行。只需启动它即可。
答案2
问题的根源是 php-fpm 没有运行(正如@Michael 指出的那样)
我还更改了位置块,因为资产未通过原始配置提供:
location ^~ /blog {
root /var/www/wordpress;
index index.php index.html index.htm;
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
#if ($uri !~ "^/images/") {
# fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
#}
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/wordpress$fastcgi_script_name;
fastcgi_pass localhost:9000;
}
}