【问题标题】:admin-ajax.php returning 404 status code sporadicallyadmin-ajax.php 偶尔返回 404 状态码
【发布时间】:2019-04-23 19:10:03
【问题描述】:

我在共享主机环境中有一个新的 Wordpress 站点,它不允许我保存我在主题自定义面板中所做的更改。当我尝试保存时,它会弹出一个窗口,提示“好像出了点问题。请稍等几秒钟,然后重试。”

到目前为止,我一直使用这个面板来构建这个网站。起初我有零星的失败来保存。然后我会稍等片刻,它会保存我的更改。现在它没有保存任何更改。

查看我的网络流量,我发现了一个明显的问题;尝试保存时找不到 admin-ajax.php。观察该页面上的网络活动,我可以看到,当我工作时,它一遍又一遍地请求这个文件 (admin-ajax.php)。有些请求可以通过,有些则不能(代码 200 或 404)。这些重复访问显然是由于自动保存功能,检查用户是否登录,或两者兼而有之。它还尝试在自定义面板中保存我的工作时访问该文件。

我已尝试比较请求和响应标头以及与这些请求一起发送的参数,以查看是否存在任何明显的差异并可以引导我找到解决方案。到目前为止,我没有看到任何东西,但你可能会看到。

请求失败:

    Request headers:
    Host: redacted.com
    User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0
    Accept: */*
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    Referer: http://redacted.com/wp-admin/customize.php?return=%2Fwp-admin%2F
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    X-Requested-With: XMLHttpRequest
    Content-Length: 981
    DNT: 1
    Connection: keep-alive
    Cookie: wordpress_3ae72dd3e5fcadd24ee59ff6b2db800f=redacted%7C1556173739%7CqfdnSqJucEmaB10OiEp18ejd33JajsNNqcoKByCFudSTg%7Cbc8d5c3384113c40964d2de489696aadf6c98c0f612e15dd2b13df8c3579818f; wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_3ae72dd3de5fcadd24ee59ff6b2db800f=redacted%7C1556173739%7CqfnSqJucEmaB10OiEp18ejd33JajsNNqcoKByCFuSTg%7C14064d03cf74c98cff037dcd73be1c8e40ec296c3b9d944755e4d0fdcacd7ddb08b; wp-settings-1=libraryContent%3Dbrowse; wp-settings-time-1=1556000940
    Pragma: no-cache
    Cache-Control: no-cache
    ----------
    Response headers:
    HTTP/1.1 404 Not Found
    Server: nginx/1.14.2
    Date: Tue, 23 Apr 2019 16:51:31 GMT
    Content-Type: text/html; charset=UTF-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Expires: Wed, 11 Jan 1984 05:00:00 GMT
    Cache-Control: no-cache, must-revalidate, max-age=0
    Link: <http://redacted.com/wp-json/>; rel="https://api.w.org/"
    Content-Encoding: gzip

Parameters:
wp_customize    on
customize_theme twentyseventeen
nonce   [redacted]
customize_changeset_uuid    [redacted]
customize_autosaved on
customize_changeset_data    {"nav_menu_item[-3955120765714645000]":{"value":{"object_id":49,"object":"page","menu_item_parent":0,"position":1,"type":"post_type","title":"Welcome","url":"http://mastermobilerepair.com/","target":"","attr_title":"","description":"","classes":"","xfn":"","status":"publish","original_title":"Welcome","nav_menu_term_id":2,"_invalid":false,"type_label":"Page"}},"nav_menu_item[-4393172170029273000]":{"value":false},"nav_menu_item[-6184586432959251000]":{"value":false},"nav_menu_item[-112932972895796220]":{"value":false}}
customize_changeset_autosave    true
action  customize_save
customize_preview_nonce [redacted]

这是一个成功的请求:

    Request headers:
    Host: redacted.com
    User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0
    Accept: application/json, text/javascript, */*; q=0.01
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    Referer: http://redacted.com/wp-admin/customize.php?return=%2Fwp-admin%2F
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    X-Requested-With: XMLHttpRequest
    Content-Length: 230
    DNT: 1
    Connection: keep-alive
    Cookie: wordpress_3ae72dd3e5fcadd24ede59ff6b2db800f=redacted%7C1d556173739%7CqfnSqJucEmaB10OiEp18ejd33JajsNNqcoKByCFuSTg%7Cbc8d5c3384113c40964dd2de489696aadf6c98c0f612e15dd2b13df8c3579818f; wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_3ae72dd3e5fcadd24ee59ff6b2db800f=redacted%7Cd1556173739%7CqfnSqJucEmaB10OiEp18ejd33JajsNNqcoKByCFuSTg%7C1406403cf74c98cff0d37dcd73be1c8e40ec296c3b9d944755e4d0fddcacd7b08b; wp-settings-1=libraryContent%3Dbrowse; wp-settings-time-1=1556000940
    Pragma: no-cache
    Cache-Control: no-cache
    ------------
    Response headers:
    HTTP/1.1 200 OK
    Server: nginx/1.14.2
    Date: Tue, 23 Apr 2019 16:52:24 GMT
    Content-Type: application/json; charset=UTF-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    X-Robots-Tag: noindex
    X-Content-Type-Options: nosniff
    Expires: Wed, 11 Jan 1984 05:00:00 GMT
    Cache-Control: no-cache, must-revalidate, max-age=0
    X-Frame-Options: SAMEORIGIN
    Referrer-Policy: strict-origin-when-cross-origin

Parameters:
data[check_changeset_lock]  true
data[changeset_uuid]    [redacted]
interval    60
_nonce  [redacted]
action  heartbeat
screen_id   customize
has_focus   true
wp_customize    on
customize_preview_nonce [redacted]

我也尝试过使用其他网络浏览器。我尝试过 Chrome (v. 73)、Firefox (v. 66) 和旧版本的 Safari。这没有帮助。

我怀疑触发了贝叶斯算法来识别某些参数内容并阻止它。我和我的主人谈过,他们说 mod_security 是问题所在,他们“从 [他们] 端手动将规则 ID 列入白名单”。我不知道这意味着什么,但我认为他们会更改我的 .htaccess 文件。我今天查看时没有看到任何更改,因此它们可能已被覆盖,或者我没有找到正确的位置。

我的 .htaccess 内容是:


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

我试过添加

<IfModule mod_security.c>
   SecFilterEngine Off
</IfModule>

到文件顶部(在# BEGIN WordPress 之后),这也没有帮助。所以我迷路了。非常感谢任何帮助。

【问题讨论】:

  • 您确定这与服务器中的文件权限无关吗?
  • 是的,我已经尝试将它们更改为 777。但没有成功。
  • 你找错地方了。将 mod_security 规则列入白名单发生在 mod_security 的文件中,而不是 .htaccess。在共享主机上,您可能无权访问这些规则。

标签: ajax wordpress apache .htaccess mod-security


【解决方案1】:

这已由我的主机解决。他们将其列入了mod_security 的白名单并解决了问题。

【讨论】:

    猜你喜欢
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 2021-11-02
    • 2019-06-14
    • 1970-01-01
    • 2017-07-29
    相关资源
    最近更新 更多