Symbolic link not allowed or link target not accessible
Symbolic link not allowed or link target not accessible
Suse10.3の環境にて
CapistranoでのApache+Mongrel+proxy_balancerの構成にて、Railsアプリ構築をやってる際にものすごくはまった事象。
静的コンテンツ(画像等)はmongrelではなくApacheで見るようにhttpd.confを書いていたわけだが、うまくできなかった。その際上記エラーが発生していた。
Capistranoを利用すると、静的コンテンツは{$INSTALL_DIR}/current/public に配置される。このcurrentというディレクトリは実はシンボリックリンクであり、このディレクトリ内をApacheから参照させるためには、
で、以下のように設定してるのに、エラーは改善せず。
<Directory "/home/troopergreen/www/image/current/public"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory>
ふとしたきっかけに、/etc/apache2/httpd.confを覗いてみると、以下の記述を発見
# forbid access to the entire filesystem by default <Directory /> Options None AllowOverride None Order deny,allow Deny from all </Directory>
もしや、こいつが全体に影響しているのではないかと。
で、Options FollowSymLinksに書き換えたらビンゴ。
おいおい、これで数時間時間を食ってしまったじゃないか。。
最終的には、/etc/apache2/httpd.confを修正するのではなく、/etc/apache2/conf.d/配下の独自の設定ファイル内で上記ディレクティブを上書きすることで対応。
<VirtualHost *:80> ServerName troopergreen.jp ServerAlias troopergreen DocumentRoot /home/troopergreen/www/image/current/public <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory> <Directory "/home/troopergreen/www/image/current/public"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> RewriteEngine On # Check for maintenance file. Let apache load it if it exists RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteRule . /system/maintenance.html [L] # Let apache serve static files #RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f #RewriteRule (.*) $1 [L] # Don't do forward proxying ProxyRequests Off # Enable reverse proxying #<Proxy *> # Order deny,allow # Allow from all #</Proxy> # Pass other requests to mongrel instance ProxyPass /images ! ProxyPass /stylesheets ! ProxyPass /javascripts ! ProxyPass / balancer://mongrel_cluster/ ProxyPassReverse / balancer://mongrel_cluster/ <Proxy balancer://mongrel_cluster> BalancerMember http://127.0.0.1:3000 BalancerMember http://127.0.0.1:3001 BalancerMember http://127.0.0.1:3002 </Proxy> # Deflate AddOutputFilterByType DEFLATE text/html text/plain text/css # ... text/xml application/xml application/xhtml+xml text/javascript BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Uncomment for deflate debugging #DeflateFilterNote Input input_info #DeflateFilterNote Output output_info #DeflateFilterNote Ratio ratio_info #LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate #CustomLog logs/myapp_deflate_log deflate </VirtualHost>
pidがないとかなんとかでmongrelを操作できない。
なんかcapistranoでmongrelの操作を行おうとした際に、なぜか以下のエラーで失敗する。
*** [err :: 10.7.163.233] Couldn't find any pid file in '/home/troopergreen/www/image/current/tmp/pids' matching 'dispatch.[0-9]*.pid' *** [err :: 10.7.163.233] *** [err :: 10.7.163.233] (also looked for processes matching "/home/troopergreen/www/image/current/public/dispatch.fcgi") *** [err :: 10.7.163.233]
本来であれば、{$install_dir}/current/tmp/pids/配下にプロセスIDが記述されたファイルが存在しているはずなのだが、なぜか空っぽ。(なぜこうなったかは不明)
おそらくmongrelはkillコマンドで強制的にプロセスを落としている模様。だからpidがわからなければ何にもできない。
結局、killコマンドで直接落としました。
その後復旧。