将wordpress添加到rails中构建的站点中

时间:2012-04-25 17:45:56

标签: ruby-on-rails wordpress

我正在尝试将一个Wordpress博客添加到一个在ruby on rails上构建的网站中。我只需要它在子目录中。我在公共目录中创建了一个文件夹并将Wordpress文件放在那里,现在我遇到了路由错误,我真的不熟悉rails。有人可以帮我找到办法吗?

1 个答案:

答案 0 :(得分:0)

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

我的安装使用NGINX作为Web服务器,使用Unicorn for 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's url rewriting功能才能让wordpress'永久链接功能正常工作。

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