5

我正在尝试将 Wordpress 博客添加到使用 ruby​​ on rails 构建的网站中。我只需要它位于子目录中。我在公共目录中创建了一个文件夹并将 Wordpress 文件放在那里,现在我遇到了路由错误,而且我真的对 Rails 不太熟悉。有人可以帮我想办法做到这一点吗?

4

1 回答 1

0

如果您有权访问服务器配置,则可以让 PHP 和 rails 在同一个项目中工作。我能够在短短几分钟内完成测试 VPS 的工作。我没有使用 wordpress 进行测试,只是一个简单的 phpinfo() 调用,但我看不出它会失败的任何原因。

我的安装使用 NGINX 作为 Web 服务器,Unicorn 用于 Rails,spawn-fcgi 和 php-cgi 用于 PHP 处理。

我已经有一个可以运行的 Rails 应用程序,所以我只是在其中添加了 PHP。rails 应用程序使用 NGINX 代理对 Unicorn 的请求,因此它已经将公共目录作为静态服务。我将在下面发布我的虚拟主机文件,以便您了解它是如何完成的。

这都是在 ArchLinux VPS 上完成的,但其他发行版应该是类似的。

我的虚拟主机文件:

upstream unicorn {
  server unix:/tmp/unicorn.jrosw.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  server_name example.com www.example.com;
  root /home/example/app/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;

  location ~ \.php$ {
    try_files $uri =404;
    include /etc/nginx/conf/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/example/app/current/public$fastcgi_script$
  }
}

然后是一个小脚本来调出 php-cgi:

#!/bin/sh

# You may want to just set this to run as your app user 
# if you upload files to the php app, just to avoid
# permissions problems

if [ `grep -c "nginx" /etc/passwd` = "1" ]; then
   FASTCGI_USER=nginx
elif [ `grep -c "www-data" /etc/passwd` = "1" ]; then
   FASTCGI_USER=www-data
elif [ `grep -c "http" /etc/passwd` = "1" ]; then
   FASTCGI_USER=http
else
# Set the FASTCGI_USER variable below to the user that
# you want to run the php-fastcgi processes as

FASTCGI_USER=
fi

# Change 3 to the number of cgi instances you want.

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 3 -u $FASTCGI_USER -f /usr/bin/php-cgi

我遇到的唯一问题是让 fastcgi_index 选项正常工作,因此您可能需要研究nginx 的 url 重写功能才能让 wordpress 的永久链接功能正常工作。

我知道这种方法并不理想,但希望它能让你走上正轨。

于 2012-04-27T11:26:14.917 回答