Nginx 経由で WordPress と Laravel アプリケーションの両方をホストする

Nginx 経由で WordPress と Laravel アプリケーションの両方をホストする

残念ですが、WordPress と Laravel アプリケーションを共存させるだけでなく、お互いの状態を認識するようにしなければなりません。WordPress プラグイン、Laravel パッケージ、Apache 構成を介してこの機能を実現していますが、今度は Web サーバーとして nginx を使用するように構成を変換する必要があります。

私のリポジトリは次のように設定されています:

/src- laravel アプリケーション。/public の下にはアプリケーションへの index.php エントリポイントが含まれています。

/wordpress- ワードプレスアプリケーション

必要な機能を正確に実行する次の Apache VirtualHost 構成があります。

<VirtualHost *:80>
    ServerName app.local
    DocumentRoot /var/www/vhosts/app.local/wordpress
    ErrorLog /var/www/vhosts/logs/app_local_error_log

     <Directory "/var/www/vhosts/app.local/wordpress">
         Options Indexes FollowSymlinks MultiViews
         AllowOverride All
         Require all granted
         DirectoryIndex index.php
    </Directory>

    <Directory /var/www/vhosts/app.local/src/public>
            DirectoryIndex index.php
            Options FollowSymLinks MultiViews
            AllowOverride All
    </Directory>

     Alias /xyz /var/www/vhosts/app.local/src/public

     <Location "/xyz">
         AllowOverride All
     </Location>
</VirtualHost>

特に /xyz の下にあるものはすべて laravel によって処理されます。ルートを含むその他すべては wordpress によって処理されます。

これが私の nginx 設定です (laravel/homestead ボックスを使用してローカルでテストしています):

server {
listen 80;
server_name .app.local;
root "/home/vagrant/code/app/wordpress";

index index.html index.htm index.php;

charset utf-8;

location /xyz/ {
    alias /home/vagrant/code/app/src/public/;
    try_files $uri $uri/ /index.php?$query_string;
}

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /var/log/nginx/app.local-error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~ /\.ht {
    deny all;
}
}

かなり近づいているように感じますが、 または を使用したり、パスの末尾にスラッシュを追加したり、場所の指示を再配置したりしても、WordPress がリクエストを処理してしまうようですaliasroot私は、これをデバッグするための nginx の知識が足りず、構成上の代替手段もわかりません。どなたか助けていただければ幸いです。

また、ここで示すように、特定の場所のディレクティブを設定し、fastcgi に渡すパラメータをカスタマイズしてみましたが、効果がないようです。

https://gist.github.com/mnshankar/9642844

関連情報