admin-ajax.php偶尔返回404状态代码

时间:2019-04-23 19:10:03

标签: ajax wordpress apache .htaccess mod-security

我在共享主机环境上有一个新的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]

我也尝试过使用其他Web浏览器。我曾经尝试过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之后),这也没有帮助。所以我迷路了。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

这已由我的房东解决。他们将其列入mod_security的白名单中,然后解决了该问题。