【发布时间】:2019-12-22 18:11:47
【问题描述】:
我在 Laravel Forge 上的 Laravel 应用程序的子文件夹上配置 wordpress 时遇到问题(服务器由 nginx 提供支持)。
Wordpress 应用位于 /home/forge/my-domain.com/public/blog 下(my-domain.com 包含我的 laravel 应用)。
我在 SO 上尝试了其他问题的几个答案,但我不断收到错误(主要是“重定向太多”或“502 网关错误”)。
这是我当前的解决方案(取自 here - 导致 502 错误网关,也适用于我的 wordpress-app 的管理区域):
# BLOG START
location @rewriteblog {
rewrite ^(.*)$ /blog/index.php?q=$uri&$args;
}
location @rewriteblogadmin {
rewrite ^(.*)$ /blog/wp-admin/index.php?q=$uri&$args;
}
location = /blog/favicon.ico {
log_not_found off;
access_log off;
}
location = /blog/robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /blog {
try_files $uri @rewriteblog;
}
location /blog/wp-admin {
try_files $uri @rewriteblogadmin;
}
location ~ ^/(blog|blog\/wp-admin)/(.*)\.php(/|$) {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_intercept_errors on;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
#BLOG-END
另一个尝试是这样的(502 Bad Gateway):
location /blog {
root /home/forge/my-domain.com/public/blog;
index index.php;
try_files $uri $uri/ /blog/index.php?q=$uri;
}
另一个尝试是这样的(管理区域和起始页可访问,帖子导致重定向过多):
location /blog {
root /home/forge/my-domain.com/public/;
index index.php;
try_files $uri $uri/ /blog/index.php?q=$uri;
}
另一个尝试是这样的(管理区域和起始页重定向过多,可访问帖子):
location /blog {
root /home/forge/faaren.com/public/blog;
index index.php;
try_files $uri $uri/ /index.php?q=$uri;
}
任何想法如何配置我的 nginx 来完成这项工作?
【问题讨论】: