【发布时间】:2025-12-15 10:40:01
【问题描述】:
喂,
我在 nginx 上运行 wordpress 3x,我所有的 ajax 调用都被破坏了。完全相同的 wordpress 在 Apache 上运行良好。
我已通过从所有 jquery.post() 调用中删除“index.php”以某种方式修复了与 nginx 一起使用的 ajax 调用,但我无法以相同的方式修复其他调用。
基本上这些变化是: 对于 nginx 行:
jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
被替换为:
jQuery.post( '?ajax=true', form_values, function(returned_data) {
我怀疑问题出在带有重写规则的 nginx 配置文件中。你在我的配置里
if (!-e $request_filename) {
rewrite ^.+/?(/wp-.*) $1 last;
rewrite ^.+/?(/.*\.php)$ $1 last;
rewrite ^(.+)$ /index.php?q=$1 last;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /xxx/public$fastcgi_script_name;
include fastcgi_params;
}
}
【问题讨论】: