不幸的是,我被迫讓 WordPress 和 Laravel 應用程式不僅共存,還要了解彼此的狀態。我透過 wordpress 外掛程式、laravel 套件和 Apache 配置來實現此功能,但現在我需要轉換設定以使用 nginx 作為網頁伺服器。
我的存儲庫設定如下:
/src
- laravel 應用程序,其下面的 /public 包含應用程式的 index.php 入口點
/wordpress
- 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 處理。其他一切,包括 root,都由 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;
}
}
alias
我覺得我已經非常接近了,但是無論我是否使用or root
,在路徑中附加尾部斜杠,或者重新排列位置指令,wordpress 似乎仍然最終會處理請求。我只是不太了解 nginx 來調試這個,或者我的替代方案是配置方面的。任何幫助將不勝感激!
我還嘗試設定特定的位置指令並自訂傳遞給 fastcgi 的參數,如這裡所示,但這似乎沒有效果: