5

ruby on rails で構築されたサイトに Wordpress ブログを追加しようとしています。サブディレクトリに置く必要があるだけです。public ディレクトリにフォルダーを作成し、そこに Wordpress ファイルを配置しましたが、ルーティング エラーが発生し、Rails にあまり詳しくありません。誰かがこれを行う方法を理解するのを手伝ってくれますか?

4

1 に答える 1

0

サーバー構成にアクセスできる場合は、PHPとレールを同じプロジェクトで機能させることができます。ほんの数分でテストVPSで動作させることができました。私はwordpressでテストせず、単純なphpinfo()呼び出しだけでしたが、失敗する理由はわかりません。

私のインストールでは、WebサーバーにNGINX、RailsにUnicorn、PHP処理にspawn-fcgiとphp-cgiを使用しています。

私はすでにRailsアプリを動作させていたので、それにPHPを追加しました。railsアプリはNGINXを使用してリクエストをUnicornにプロキシするため、すでにパブリックディレクトリを静的として提供していました。以下に仮想ホストファイルを投稿して、それがどのように行われたかを確認できるようにします。

これはすべてArchLinuxVPSで行われましたが、他のディストリビューションも同様である必要があります。

私の仮想ホストファイル:

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オプションを機能させることでした。そのため、wordpressのパーマリンク機能を機能させるには、おそらくnginxのURL書き換え機能を調べる必要があります。

この方法は理想的ではないことは承知していますが、うまくいけば正しい方向に進むことができます。

于 2012-04-27T11:26:14.917 に答える