私はapache-tomcatを使用しています。私の solr は私の localhost で正常に動作します.今私はそれをオンラインにしたいです.私のWebホストdirのsolr。事前に感謝します
1 に答える
2
まず、認証を要求することで、Tomcat Web 管理 GUI 全体を保護します。最初に、/etc/tomcat6/tomcat-users.xml で新しいユーザーを作成します。
<tomcat-users>
<role rolename="admin"/>
<role rolename="manager"/>
<role rolename="proxyUsers"/>
<user username="jorno" password="XXXXX" roles="admin,manager,proxyUsers"/>
<user username="proxyUser" password="XXXXXX" roles="proxyUsers"/>
</tomcat-users>
ファイル /etc/tomcat6/web.xml にセキュリティ制約を追加します
<security-constraint>
<web-resource-collection>
<web-resource-name>
Solr authenticated application
</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>solrUsers</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Basic Authentication</realm-name>
</login-config>
<security-role>
<description>solr users</description>
</security-role>
tomcatを再起動することを忘れないでください
/etc/init.d/tomcat6 restart
Tomcat solr アプリケーションの Web GUI にアクセスし、認証が機能することを確認します。
次に、Apache で実際のプロキシを作成します。まず、簡単なサイトを作成します。PHPが必要です。次の vhost の例はそのトリックを行います。書き換えに注意してください。
q.example.com - Solr 検索エンジン プロキシ
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/q.example.com
ServerName q.example.com
ServerAlias solr.example.com
AddDefaultCharset UTF-8
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
# REWRITES
RewriteEngine on
# Debug:
# RewriteLog /tmp/rwlog
# RewriteLogLevel 9
RewriteRule ^/([^/]+)/? /index.php [NC,L]
</VirtualHost>
Apacheをリロードすることを忘れないでください
/etc/init.d/apache2 reload
次に、サイトのルートに index.php ファイルを作成します。インデックスを更新する頻度によっては、ユーザーにプロキシのコンテンツをキャッシュさせたい場合があります。ここでは 5 分に設定しました。
<?php
// Avvoid too long client cache
// calc an offset of 5 minutes
$offset = 60 * 5;
// calc the string in GMT not localtime and add the offset
$expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
//output the HTTP header
Header($expire);
// Write the result from solr
Echo file_get_contents('http://proxyUser:[password]@127.0.0.1:8080/solr/select?'.$_SERVER["QUERY_STRING"]);
?>
それだけです。プロキシを次のようにテストできるようになりました
http://q.example.com/select?q= %3A &indent=on
于 2013-07-24T13:42:23.990 に答える