2017-03-01 5 views
2

これは動作しているかどうかはわかりませんが、試しましたが効果はありませんでした。だからエラーはありませんが、何かが間違っているようです。私が欲しいものこのURLでLaravel APIを取得するためのApache設定:www.example.com/api

は私のAPI(Laravel 5.4)は、このルートURLを得ることである:ここではwww.example.com/api

は私の考えに合うものです:

<VirtualHost \*:80> 
    ServerName example.com 
    DocumentRoot /var/www/vhosts/angular-client 
</VirtualHost>  

<VirtualHost>  
    ServerName example.com/api 
    DocumentRoot /var/www/vhosts/api/public 
</VirtualHost> 

任意の提案は大歓迎です。

敬具、

ジョセフGremaud

EDIT: はちょうどそれは、このようなエイリアスでディレクトリを使用する方が簡単ですが判明:

<VirtualHost *:80> 
     DocumentRoot /var/www/spmo 
     ServerName  spmo.corp.sftcm.ch 
     Header set Access-Control-Allow-Origin "*" 
<Directory /var/www/spmo> 
     Require all granted 
     DirectoryIndex index.html 
     Options +Indexes 
</Directory> 
Alias /api /var/www/api/public 
<Directory /var/www/api/public> 
     Require all granted 
     Options +Indexes 
     DirectoryIndex index.php index.html 
</Directory> 
</VirtualHost> 

今だけの問題があるためLaravelの設定のまますべてのルートが次のようにリダイレクトされています:

期待:spmo.corp.sftcm.ch/api/api/v1/teams-> should should g JSONの応答をお願いします。 結果:spmo.corp.sftcm.ch/api/api/v1/teams-> 404エラーが表示されました。

私はこれがapi/apiを持つのはうれしくないと知っていますが、問題を解決するときにlaravel接頭辞を変更します。

答えて

1

あなたはVirtualHostディレクティブ上の仮想ホスト引数のIPが欠落している:あなたは、エラーのこれらの種類を確認するために、コンソール上でjournalctl | tailを使用することができます

<VirtualHost \*:80>  
    ServerName example.com/api 
    DocumentRoot /var/www/vhosts/api/public 
</VirtualHost> 

+0

私はこのサーバ上に1つのIPしか持っていないので、私はIPを使う必要はありません。*:80は意図しているサーバ自身のIPを自動的に参照します。 私はApacheの設定を初めて行ったので、私の場合は強く推奨されているかどうかはわかりません –

関連する問題