将wordpress添加到内置Rails的网站中

5 wordpress ruby-on-rails

我正在尝试将Wordpress博客添加到使用Rails构建的Ruby网站中。我只需要它在子目录中。我在公共目录中创建了一个文件夹,并将Wordpress文件放在其中,现在我遇到了路由错误,而且我对Rails真的不那么熟悉。有人可以帮我找出解决方法吗?

jro*_*osw 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$
  }
}
Run Code Online (Sandbox Code Playgroud)

然后是一个启动 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
Run Code Online (Sandbox Code Playgroud)

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

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