2016-11-16 9 views
0

ApacheでLaravel 5.3アプリケーションへのアクセスを制限しようとしています。Laravel .htaccess rewriteとapache2位置指示

私のアプリは社内で利用可能ですが、さまざまな外部ソースからポストバックを受け取ります。 NATを無効にしたポート転送が設定されているので、内部から外部要求を伝えることができます。

example.com/api/external/ ...がURLの場合を除いて、すべてのURLに403が表示されます。私はまださえ許さ上で403を取得し、外部アドレスから任意のURLにアクセスするたびに、私は次のhtaccess(Laravel 5.3のデフォルト)

<IfModule mod_rewrite.c> 
<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

RewriteEngine On 

# Redirect Trailing Slashes If Not A Folder... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# Handle Front Controller... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [L] 

# Handle Authorization Header 
RewriteCond %{HTTP:Authorization} . 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

私のバーチャルホストの設定

<Directory /var/www/mailer/public/> 
      Options Indexes FollowSymLinks 
      AllowOverride All 
      Require all granted 
    </Directory> 

    <Location /> 
      Order deny,allow 
      deny from all 
      allow from 10.64.1.0/24 
      allow from 10.64.20.0/24 
    </Location> 

    <Location /api/external/smsPost> 
      Allow from all 
    </Location> 

を持っていますロケーション。

You don't have permission to access /index.php on this server. 

それはhtaccessファイルに問題があると場所のディレクティブは、この目的のために働いていないことも、example.com/api/external/smsPostに/index.phpたので、私は思います。この指令で必要なものを達成できる方法はありますか?

多くのありがとうございます。

答えて

0

laravelミドルウェアを使用して制限されたルートにバインドしてみませんか?

public function handle($request, Closure $next) 
{ 

    if(Route::getCurrentRoute()->getPath() == "api/external/") 
      return response('You don't have permission to access /index.php on this server.', 403); 

    // return the $next closure, so other Middlewares can run 
    return $next($request); 
}