wordpress403_如何修复WordPress中的403禁止错误

wordpress403

Are you dealing with the 403 Forbidden error on your WordPress site? It is one of the most dreadful errors that a WordPress beginner can come across. In this article, we will show you how to easily fix the 403 forbidden error in WordPress.

您是否正在处理WordPress网站上的403 Forbidden错误? 这是WordPress初学者可能遇到的最可怕的错误之一。 在本文中,我们将向您展示如何轻松修复WordPress中的403禁止错误。

Fixing 403 Forbidden error in WordPress
什么是WordPress中的403禁止访问拒绝错误? (What is a 403 Forbidden – Access Denied Error in WordPress?)

WordPress shows codes and messages when an error occurs on your website. See our list of most common WordPress errors and how to fix them.

当您的网站上发生错误时,WordPress会显示代码和消息。 请参阅我们最常见的WordPress错误列表以及如何修复它们

403 Forbidden status code shown on a WordPress site

403 Forbidden error code is shown when your server permissions don’t allow access to a specific page.

当您的服务器权限不允许访问特定页面时,将显示403禁止错误代码。

This is why the error is usually accompanied by the text:

这就是错误通常伴随文本的原因:

403 Forbidden – You don’t have permission to access ‘/’ on this server.

403禁止访问–您无权访问此服务器上的“ /”。

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

此外,尝试使用ErrorDocument处理请求时遇到403 Forbidden错误。

There are different scenarios when you can see this error. For example:

在不同的情况下,您可以看到此错误。 例如:

  • wp-admin or wp-adminWordPress login page.WordPress登录页面上拒绝访问。
  • WordPress install.WordPress安装期间。
  • 403 Forbidden error when visiting any page on your WordPress site.

    当访问WordPress网站上的任何页面时,出现403禁止错误。
  • ‘Access Denied’ instead of full 403 Forbidden status.“访问被拒绝”,而不是完整的403禁止状态。
  • You may also see ‘Access to yourdomain.com was denied. You don’t have authorization to view this page.’

    您可能还会看到“拒绝访问yourdomain.com。 您无权查看此页面。”

Now that you know about the different types of 403 errors, let’s talk about what causes this error.

现在您已经了解了403错误的不同类型,下面我们来讨论导致此错误的原因。

是什么导致WordPress中的403禁止错误? (What Causes 403 Forbidden Error in WordPress?)

The most common cause for the 403 Forbidden error in WordPress is due to poorly configured security plugins. Many WordPress security plugins can block an IP address (or a whole range of IP addresses) if they believe them to be malicious.

WordPress中出现403 Forbidden错误的最常见原因是由于安全插件配置不良。 如果许多WordPress安全插件认为它们是恶意的,则可以阻止其IP地址(或整个IP地址范围)。

This is why we use Sucuri to improve security of all our WordPress sites.

这就是为什么我们使用Sucuri来提高我们所有WordPress网站的安全性的原因。

Another possible cause could be a corrupt .htaccess file or incorrect file permissions on your server.

另一个可能的原因可能是.htaccess文件损坏或服务器上的文件权限不正确

Your WordPress hosting company can sometimes make accidental changes to their server settings. This may result in 403 Forbidden error on your site.

您的WordPress托管公司有时可能会意外更改其服务器设置。 这可能会在您的网站上导致403禁止错误。

Having said that, let’s take a look at how to solve 403 forbidden error in WordPress.

话虽如此,让我们看一下如何解决WordPress中的403禁止错误。

影片教学 (Video Tutorial)

演示地址

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

在WordPress中修复403禁止的错误 (Fixing 403 Forbidden Error in WordPress)

Before you do anything, we recommend that you create a complete WordPress backup of your website. Here is our guide on how to manually create a WordPress backup.

在执行任何操作之前,我们建议您创建网站的完整WordPress备份。 这是我们有关如何手动创建WordPress备份的指南

If you were already using an automatic WordPress backup plugin, then make sure that you have access to a latest backup before moving forward.

如果您已经在使用WordPress自动备份插件 ,请在继续操作之前确保您可以访问最新的备份。

1.修复WordPress插件导致的403禁止错误 (1. Fixing 403 Forbidden Error Caused by a WordPress Plugin)

First thing you need to do is to temporarily deactivate all WordPress plugins. This includes any security plugins that you may have installed on your site.

您需要做的第一件事是暂时停用所有WordPress插件 。 这包括您可能已在网站上安装的所有安全性插件。

If this resolves your problem, then this means one of the plugins on your website was causing this error.

如果这可以解决您的问题,则表明您网站上的一个插件引起了此错误。

You can figure out which plugin was causing the error by activating all your plugins one at a time until you are able to reproduce the 403 forbidden error.

您可以一次激活所有插件,直到能够重现403禁止的错误,然后找出导致该错误的插件。

2.修复.htaccess文件损坏导致的403禁止错误 (2. Fix 403 Forbidden Error Caused by Corrupt .htaccess File)

Often the 403 error is caused by a corrupt .htaccess file in your WordPress site. Repairing this file is quite easy.

403错误通常是由WordPress网站中的.htaccess文件损坏引起的。 修复此文件非常容易。

First you need to connect to your website using a FTP client or file manager in cPanel.

首先,您需要使用cPanel中的FTP客户端或文件管理器连接到您的网站。

Next, locate the .htaccess file in the root folder of your WordPress site. See this guide if you can’t find .htaccess file in Your WordPress folder.

接下来,在WordPress网站的根文件夹中找到.htaccess文件。 如果您在WordPress文件夹中找不到.htaccess文件,请参阅本指南。

You need to download the .htaccess file to your computer so that you have a fresh backup of it. After that, you need to delete the file from your server.

您需要将.htaccess文件下载到计算机上,以便对其进行全新备份。 之后,您需要从服务器中删除文件。

Delete .htaccess file from your WordPress site

Try accessing your website. If 403 forbidden error is resolved, then this means that your .htaccess file was corrupt.

尝试访问您的网站。 如果403禁止错误得到解决,则意味着您的.htaccess文件已损坏。

You can generate a fresh .htaccess file by logging into your WordPress admin area and going to Settings » Permalinks page.

您可以通过登录WordPress管理区域并转到“设置”»“永久链接”页面来生成新的.htaccess文件。

Regenerating .htaccess file in WordPress

Simply click on the Save Changes button at the bottom of the page and WordPress will generate a fresh .htaccess file.

只需单击页面底部的“ 保存更改”按钮,WordPress就会生成一个新的.htaccess文件。

3.修复WordPress中文件权限引起的403禁止错误 (3. Fix 403 Forbidden Error Caused by File Permissions in WordPress)

All files stored on your website have file permissions. These file permissions control who can access files and folders on your website.

网站上存储的所有文件均具有文件许可权。 这些文件权限控制谁可以访问您网站上的文件和文件夹。

Incorrect file permissions can cause 403 forbidden error. It makes your web server thinks that you do not have permission to access those files.

不正确的文件权限可能导致403禁止错误。 它使您的Web服务器认为您没有访问这些文件的权限。

If the above two solutions do not solve the 403 forbidden error on your site, then incorrect file permissions can be the most likely cause.

如果以上两种解决方案都不能解决您网站上的403禁止错误,则最可能的原因是文件权限错误。

You can ask your WordPress hosting provider to check your website for correct file permissions. Some hosts are very supportive, they wouldn’t mind and will probably fix that for you.

您可以要求WordPress托管提供商检查您的网站是否具有正确的文件权限。 一些主持人非常支持,他们不介意并且可能会为您解决该问题。

Changing file permissions yourself can have serious consequences. If you do not feel confident doing it yourself, then ask a friend for help or hire a professional.

自行更改文件权限可能会导致严重后果。 如果您对自己做的事情没有信心,请向朋友寻求帮助或聘请专业人员。

However, if you want to do it yourself, then here is how you would check your file permissions.

但是,如果您想自己执行此操作,则可以按以下方法检查文件权限。

Simply connect to your WordPress site using an FTP client. Navigate to the root folder containing all your WordPress files.

只需使用FTP客户端连接到您的WordPress网站即可。 导航到包含所有WordPress文件的根文件夹。

Checking file permissions

Click to select a folder, right click and then select File Permissions from the menu.

单击以选择一个文件夹,右键单击,然后从菜单中选择“文件权限”。

Your FTP client will show you a file permissions dialog box like this:

您的FTP客户端会显示一个文件权限对话框,如下所示:

Changing file permissions using FTP

All folders on your WordPress site should have a file permission of 744 or 755.

WordPress网站上的所有文件夹应具有744或755的文件许可权。

All files on your WordPress site should have a file permission of 644 or 640.

WordPress网站上的所有文件都应具有644或640的文件许可权。

You can set the file permission to the root folder to 744 or 755. Check the box next to ‘Recurse into subdirectories’ and then check the option that says ‘apply to directories only’.

您可以将根文件夹的文件权限设置为744或755。选中“递归到子目录”旁边的框,然后选中“仅应用于目录”选项。

Click on the OK button. Your FTP client will now start setting permissions to all subdirectories in that folder.

单击确定按钮。 您的FTP客户端现在将开始为该文件夹中的所有子目录设置权限。

Once it is done, you need to repeat the process for all the files. This time you will use file permission of 644 or 640 and don’t forget to select ‘Recurse into subdirectories’ and ‘apply to files only’. options.

完成后,您需要对所有文件重复该过程。 这次,您将使用文件权限644或640,并且不要忘记选择“递归到子目录”“仅应用于文件”。 选项。

Click on the OK button and your FTP client will start setting file permissions for all the selected files.

单击确定按钮,您的FTP客户端将开始为所有选定文件设置文件权限。

Try accessing your website now, and 403 forbidden error should be gone now.

现在尝试访问您的网站,并且403禁止错误现在应该消失了。

We hope this article helped you fix the 403 forbidden error in WordPress. You may also want to see our expert tips and hacks to protect your WordPress admin area.

我们希望本文能帮助您解决WordPress中的403禁止错误。 您可能还希望查看我们的专家提示和技巧,以保护WordPress管理区域

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-403-forbidden-error-in-wordpress/

wordpress403

<think>好的,我现在需要解决用户遇到的403 Forbidden错误以及ErrorDocument处理请求时出错的问题。首先,我得回忆一下Apache服务器中常见的403错误原因和解决方法。 用户提到了403 Forbidden错误,这通常与权限设置有关。可能的原因包括文件系统权限不足、目录没有索引文件、或者Apache的配置问题,比如访问控制规则。我需要一步步分析这些可能性。 首先,检查文件系统权限。Apache的运行用户(比如www-data)需要有访问网站根目录及其文件的权限。如果目录权限不是755或者文件不是644,可能会导致403错误。用户需要确认这些权限设置是否正确。 其次,目录缺少默认索引文件。例如,如果访问的是一个目录,而该目录下没有index.html或index.php等文件,且Apache的配置中关闭了目录列表(Options -Indexes),就会返回403。这时候,用户要么创建索引文件,要么启用目录列表(虽然不建议这样做)。 接下来是Apache的访问控制配置。用户可能使用了Order、Allow、Deny等指令,或者更新的Require指令。需要检查.htaccess文件或主配置文件中的相关部分。例如,如果Order设置为allow,deny,但Allow规则没有匹配到请求,默认会被拒绝。此外,如果AllowOverride设置不当,可能导致.htaccess文件被忽略,从而影响权限控制。例如,引用[1]提到,当AllowOverride设置为None时,服务器会完全忽略.htaccess文件,这可能与用户的配置有关。 然后是ErrorDocument的配置问题。用户提到ErrorDocument处理请求时出错,可能需要检查ErrorDocument指令的路径是否正确,是否指向了有效的错误页面,并且该页面本身没有导致其他错误。例如,如果配置了ErrorDocument 403 /error.html,但/error.html不存在或权限不足,可能会循环报错。 另外,SELinux或AppArmor等安全模块也可能导致权限问题。需要检查是否这些安全策略阻止了Apache访问相关资源。 总结下来,解决步骤可能包括: 1. 检查文件和目录权限。 2. 确认存在索引文件或调整目录索引设置。 3. 检查Apache的访问控制配置,确保允许访问。 4. 验证ErrorDocument路径的正确性和权限。 5. 查看安全模块的日志,排除干扰。 现在需要将这些步骤以清晰的结构呈现给用户,并引用相关的参考资料,比如访问控制中的Order和Allow指令如何相互作用(引用[3]),以及.htaccess被忽略的情况(引用[1])。同时,确保回答符合用户的要求,使用正确的中文和LaTeX格式,生成相关问题,并在引用处添加标识。</think>### 403 Forbidden错误及ErrorDocument配置解决方案 #### 1. 检查文件系统权限 - **文件/目录权限**:确保Apache进程用户(如`www-data`)对网站根目录及其文件有读取权限。 - 推荐权限:目录设为$755$(`drwxr-xr-x`),文件设为$644$(`-rw-r--r--`) - 修复命令示例: ```bash chmod -R 755 /var/www/html/ chmod -R 644 /var/www/html/*.html ``` #### 2. 确认索引文件与目录访问规则 - **索引文件缺失**:若访问的是目录(如`http://example.com/files/`),需确保目录中存在`index.html`、`index.php`等默认索引文件。 - **目录列表设置**: - 若需禁用目录列表,配置`Options -Indexes`(默认行为返回403)[^3] - 若需启用目录列表,配置`Options +Indexes`(不建议暴露目录结构) #### 3. 检查Apache访问控制配置 - **`Order`与`Allow/Deny`指令**: ```apache Order allow,deny Allow from 192.168.1.0/24 Deny from all ``` - 若客户端IP未匹配`Allow`规则,默认会被`Deny`拒绝 - **新语法(Apache 2.4+)**推荐使用`Require`: ```apache Require ip 192.168.1.0/24 ``` - **`.htaccess`文件是否生效**: - 主配置中需设置`AllowOverride All`(或至少`AllowOverride AuthConfig Limit`),否则`.htaccess`规则会被忽略[^1] - 检查配置段: ```apache <Directory "/var/www/html"> AllowOverride All </Directory> ``` #### 4. 验证ErrorDocument配置 - **错误页面路径有效性**: ```apache ErrorDocument 403 /custom_403.html ``` - 确保`/custom_403.html`存在且Apache有权限读取 - 避免循环错误:若错误页面自身触发403,需简化其路径或权限 #### 5. 安全模块干扰(SELinux/AppArmor) - **SELinux**: - 临时调试:`setenforce 0` - 永久修复:调整文件上下文标签 ```bash chcon -R -t httpd_sys_content_t /var/www/html/ ``` - **AppArmor**:检查`/etc/apparmor.d/usr.sbin.apache2`中是否允许访问目标路径 #### 6. 日志分析 - **查看错误日志**: ```bash tail -f /var/log/apache2/error.log ``` - 日志会明确提示拒绝原因,如`client denied by server configuration`或权限错误 --- ### 相关问题 1. 如何通过`.htaccess`限制特定文件类型的访问? 2. Apache 2.4的`Require`指令与旧版`Order`指令有何区别? 3. SELinux如何影响Web服务器的文件访问? --- : 当`AllowOverride`设置为`None`时,服务器完全忽略`.htaccess`文件。 [^3]: 若`Order`和`Allow`/`Deny`指令同时匹配,`allow`规则优先生效。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值