Search code examples
.htaccesssolrrestriction

Protect restrict Solr Admin url from external user using .htaccess or tomcat


I have recently installed Solr on server and i want to restrict only local users can access it with .htaccess

site.com:8983/solr/admin    [ restrict all user]

And below is the .htaccess code

RewirteRule on
<FilesMatch "127.0.0.1:8983/solr/admin">
    Order Deny, Allow
    Deny form all
    Allow 127.0.0.1
</FilesMatch>

Or is there any method we can protect / restrict Solr Admin on site.com:8983/solr/admin accessing from other users Only local ip users can use it..

And i tried this one, but its not working.


Solution

  • Your <FilesMatch "127.0.0.1:8983/solr/admin"> line will never match anything because you've stuck the hostname and port in the regular expression. Try using the Location container instead:

    <Location "/solr/admin">
        Order Deny, Allow
        Deny from all
        Allow 127.0.0.1
    </Location>
    

    Or better yet, Directory:

    <Directory "/path/to/your/document/root/solr/admin"> 
        Order Deny, Allow
        Deny from all
        Allow 127.0.0.1
    </Directory>
    

    You'll need to fill in the full path to the solr/admin directory.

    Get rid of the RewirteRule on line, it doesn't do anything and it's not even spelled right and will cause a 500 error.

    However, neither of these directives can be use in an htaccess file. You need to use these in either the server of vhost config. If you must use an htaccess file, then create an htaccess file in your solr/admin directory and simply put these directives in it:

    Order Deny, Allow
    Deny from all
    Allow 127.0.0.1
    

    Or, in the htaccess file in your document root:

    RewriteEngine On
    RewriteCond %{REMOTE_ADDR} !127.0.0.1
    RewriteRule ^/?solr/admin - [L,F]