我知道这个问题以前有人提出过,但我发誓我已经读过其他帖子了。我在 Apache/2.4.7 (Ubuntu) 服务器上使用虚拟主机来托管多个 wordpress 网站。我有一个网站 SiteA,运行良好,但 SiteB (SiteBroken) 没有运行。
我通过 apt-get 安装了 apache,我的配置文件是
/etc/apache2
-rw-r--r-- 1 root root 7.3K Mar 28 15:29 apache2.conf
我已经阅读过有关在此文件内部(我不确定)或通过命令更改用户的信息chown
,以及我对 SiteA 与 SiteB 的权限
/var/www/SiteA/public_html
total 188k
drwxr-xr-x 5 root root 4.0K Mar 31 00:42 ..
-rw-r--r-- 1 root root 25K Apr 4 20:23 wp-signup.php
-rw-r--r-- 1 root root 11K Apr 4 20:23 wp-settings.php
-rw-r--r-- 1 root root 33K Apr 4 20:23 wp-login.php
-rw-r--r-- 1 root root 2.9K Apr 4 20:23 wp-cron.php
-rw-r--r-- 1 root root 7.1K Apr 4 20:23 readme.html
-rw-r--r-- 1 root root 418 Apr 4 20:23 index.php
-rw-r--r-- 1 root root 3.0K Apr 4 20:23 xmlrpc.php
-rw-r--r-- 1 root root 4.0K Apr 4 20:23 wp-trackback.php
-rw-r--r-- 1 root root 2.7K Apr 4 20:23 wp-load.php
-rw-r--r-- 1 root root 2.4K Apr 4 20:23 wp-links-opml.php
drwxr-xr-x 12 root root 4.0K Apr 4 20:23 wp-includes
-rw-r--r-- 1 root root 2.7K Apr 4 20:23 wp-config-sample.php
-rw-r--r-- 1 root root 4.9K Apr 4 20:23 wp-comments-post.php
-rw-r--r-- 1 root root 271 Apr 4 20:23 wp-blog-header.php
-rw-r--r-- 1 root root 4.9K Apr 4 20:23 wp-activate.php
-rw-r--r-- 1 root root 20K Apr 4 20:23 license.txt
-rw-r--r-- 1 root root 8.1K Apr 4 20:23 wp-mail.php
drwxr-xr-x 9 root root 4.0K Apr 4 20:23 wp-admin
drwxr-xr-x 6 www-data www-data 4.0K Apr 16 14:55 wp-content
-rw-r--r-- 1 root root 3.5K Apr 16 14:58 wp-config.php
drwxr-xr-x 5 root root 4.0K Apr 16 14:58 .
/var/www/SiteB/public_html
total 220k
-rw-r--r-- 1 root root 3.0K Jan 5 21:17 xmlrpc.php
-rw-r--r-- 1 root root 4.0K Jan 5 21:17 wp-trackback.php
-rw-r--r-- 1 root root 25K Jan 5 21:17 wp-signup.php
-rw-r--r-- 1 root root 11K Jan 5 21:17 wp-settings.php
-rw-r--r-- 1 root root 8.1K Jan 5 21:17 wp-mail.php
-rw-r--r-- 1 root root 33K Jan 5 21:17 wp-login.php
-rw-r--r-- 1 root root 2.7K Jan 5 21:17 wp-load.php
-rw-r--r-- 1 root root 2.4K Jan 5 21:17 wp-links-opml.php
-rw-r--r-- 1 root root 2.9K Jan 5 21:17 wp-cron.php
-rw-r--r-- 1 root root 4.9K Jan 5 21:17 wp-comments-post.php
-rw-r--r-- 1 root root 271 Jan 5 21:17 wp-blog-header.php
-rw-r--r-- 1 root root 4.9K Jan 5 21:17 wp-activate.php
-rw-r--r-- 1 root root 418 Jan 5 21:17 index.php
drwxr-xr-x 9 root root 4.0K Jan 5 22:11 wp-admin
-rw-r--r-- 1 root root 20K Feb 18 22:05 license.txt
drwxr-xr-x 12 root root 4.0K Mar 1 21:57 wp-includes
-rw-r--r-- 1 root root 3.4K Mar 28 23:48 wp-config.php
-rw-r--r-- 1 root root 7.1K May 7 06:30 readme.html
drwxr-xr-x 8 www-data www-data 4.0K May 7 23:08 wp-content
-rw-r--r-- 1 root root 25K May 25 06:23 error_log
-rw-r--r-- 1 root root 792 May 30 14:50 2.htaccess
-rw-r--r-- 1 root root 241 May 30 14:51 .offline.htaccess
drwxr-xr-x 6 root root 4.0K May 30 14:55 ..
drwxr-xr-x 5 root root 4.0K Jun 1 07:25 .
我已从.httaccces
SiteB 配置中删除,因为我试图消除导致我的网站收到 403 错误的变量You don't have permission to access / on this server
/etc/apache2/sites-available
cat SiteA.conf
# public: /var/www/SiteA/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster@SiteA
ServerName www.SiteA
ServerAlias SiteA
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/SiteA/public_html
# Log file locations
LogLevel warn
ErrorLog /var/www/SiteA/log/error.log
CustomLog /var/www/SiteA/log/access.log combined
</VirtualHost>
/etc/apache2/sites-available
cat SiteBroken.conf
# domain: SiteBroken
# public: /var/www/SiteBroken/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster@SiteBroken
ServerName www.SiteBroken
ServerAlias SiteBroken
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/SiteBroken/public_html
# Log file locations
LogLevel warn
ErrorLog /var/www/SiteBroken/log/error.log
CustomLog /var/www/SiteBroken/log/access.log combined
</VirtualHost>
diff SiteA.conf SiteBroken.conf
1,3c1,2
<
<
< # public: /var/www/SiteA/public_html/
---
> # domain: SiteBroken
> # public: /var/www/SiteBroken/public_html/
7,9c6,8
< ServerAdmin webmaster@SiteA
< ServerName www.SiteA
< ServerAlias SiteA
---
> ServerAdmin webmaster@SiteBroken
> ServerName www.SiteBroken
> ServerAlias SiteBroken
13c12
< DocumentRoot /var/www/SiteA/public_html
---
> DocumentRoot /var/www/SiteBroken/public_html
16,17c15,16
< ErrorLog /var/www/SiteA/log/error.log
< CustomLog /var/www/SiteA/log/access.log combined
---
> ErrorLog /var/www/SiteBroken/log/error.log
> CustomLog /var/www/SiteBroken/log/access.log combined
19,20d17
<
/etc/apache2/sites-available
total 44K
-rw-r--r-- 1 root root 6.3K Jan 7 2014 default-ssl.conf
-rw-r--r-- 1 root root 1.4K Jan 7 2014 000-default.conf
-rw-r--r-- 1 root root 626 Mar 31 00:42 SiteA.conf
drwxr-xr-x 8 root root 4.0K Jun 1 07:13 ..
-rw-r--r-- 1 root root 713 Jun 1 07:16 SiteBroken.conf
drwxr-xr-x 2 root root 4.0K Jun 1 07:16 .
我昨天在排除故障时在错误日志中注意到了此错误消息。
/var/www/SiteBroken/log$ cat error.log
[Tue Mar 31 03:22:14.410438 2015] [:error] [pid 25622] [client 113.123.33.183:47379] script '/var/www/SiteBroken/public_html/phpinfo.php' not found or unable to stat
phpinfo.php
运行良好的 SiteA 拥有所有相同的 wordpress 文件等,但SiteA 目录中没有文件,我不确定为什么一个站点正在运行,但我无法查看 SiteB
我最近将整个 public_html 目录 chown 到 www-data,但这仍然无法解决 403 错误消息。
sudo chown -R www-data:www-data /var/www/SiteBroken/public_html/
drwxr-xr-x 5 www-data www-data 4.0K Jun 1 07:25 public_html
启用日志级别调试我所看到的只是停止并重新启动 apache 的输出,以及缺少的 `/var/www/html/moadmin.php' 文件以及此文件是否必要
[Mon Jun 01 07:25:38.832460 2015] [mpm_prefork:notice] [pid 9847] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Mon Jun 01 07:25:38.832538 2015] [core:notice] [pid 9847] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jun 01 08:27:58.649847 2015] [mpm_prefork:notice] [pid 9847] AH00169: caught SIGTERM, shutting down
[Mon Jun 01 08:27:59.551789 2015] [mpm_prefork:notice] [pid 10198] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Mon Jun 01 08:27:59.551885 2015] [core:notice] [pid 10198] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jun 01 10:43:46.042411 2015] [:error] [pid 10208] [client 89.248.172.27:51451] script '/var/www/html/moadmin.php' not found or unable to stat
[Tue Jun 02 07:53:47.086020 2015] [mpm_prefork:notice] [pid 10198] AH00169: caught SIGTERM, shutting down
[Tue Jun 02 07:53:48.203046 2015] [mpm_prefork:notice] [pid 12370] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Tue Jun 02 07:53:48.203105 2015] [core:notice] [pid 12370] AH00094: Command line: '/usr/sbin/apache2'
[Tue Jun 02 07:57:14.417485 2015] [mpm_prefork:notice] [pid 12370] AH00169: caught SIGTERM, shutting down
[Tue Jun 02 07:57:15.280777 2015] [mpm_prefork:notice] [pid 12515] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Tue Jun 02 07:57:15.280852 2015] [core:notice] [pid 12515] AH00094: Command line: '/usr/sbin/apache2'
[Tue Jun 02 07:59:45.902752 2015] [mpm_prefork:notice] [pid 12515] AH00169: caught SIGTERM, shutting down
[Tue Jun 02 07:59:47.017507 2015] [mpm_prefork:notice] [pid 12653] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Tue Jun 02 07:59:47.017577 2015] [core:notice] [pid 12653] AH00094: Command line: '/usr/sbin/apache2'
[Tue Jun 02 08:05:59.014895 2015] [mpm_prefork:notice] [pid 12653] AH00169: caught SIGTERM, shutting down
[Tue Jun 02 08:06:00.124043 2015] [mpm_prefork:notice] [pid 12787] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Tue Jun 02 08:06:00.124101 2015] [core:notice] [pid 12787] AH00094: Command line: '/usr/sbin/apache2'
[Tue Jun 02 08:23:09.214883 2015] [mpm_prefork:notice] [pid 12787] AH00169: caught SIGTERM, shutting down
[Tue Jun 02 08:23:10.332498 2015] [mpm_prefork:notice] [pid 13039] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Tue Jun 02 08:23:10.332556 2015] [core:notice] [pid 13039] AH00094: Command line: '/usr/sbin/apache2'
[Tue Jun 02 08:40:06.186778 2015] [mpm_prefork:notice] [pid 13039] AH00169: caught SIGTERM, shutting down
[Tue Jun 02 08:40:07.305531 2015] [mpm_prefork:notice] [pid 13491] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.7 configured -- resuming normal operations
[Tue Jun 02 08:40:07.305595 2015] [core:notice] [pid 13491] AH00094: Command line: '/usr/sbin/apache2'
更新: ls -la
/var/www$ ls -la
total 48
drwxr-xr-x 7 root root 4096 Jun 2 08:21 .
drwxr-xr-x 14 root root 4096 Mar 28 14:40 ..
drwxr-xr-x 5 root root 4096 Mar 31 00:42 SiteA (working website)
drwxr-xr-x 2 root root 4096 May 30 12:50 html
drwxr-xr-x 6 root www-data 4096 May 30 14:55 SiteBroken
2015 年 6 月 6 日更新
在阅读了其他几篇 SE 帖子后,我修改了该apache.conf
文件,如下所示:
<Directory />
Options FollowSymLinks
AllowOverride all
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
我甚至在其中添加了我的完整文档根目录来测试所有内容:
<Directory /var/www/html/SiteBroken/public_html>
Options FollowSymLinks
AllowOverride all
Require all granted
</Directory>
现在,当我将浏览器指向 URL 时,我的 SiteBroken 确实会出现并生成,但是,现在我无法导航到任何页面,即www.sitebroken.com/foo
或www.sitebroken.com/bar
我被告知我的虚拟服务器无法读取 php 文件?是这样吗?
/var/www/html/SiteBroken/public_html$
total 188K
-rw-r--r-- 1 root root 3.0K Apr 4 20:23 xmlrpc.php
-rw-r--r-- 1 root root 4.0K Apr 4 20:23 wp-trackback.php
-rw-r--r-- 1 root root 25K Apr 4 20:23 wp-signup.php
-rw-r--r-- 1 root root 11K Apr 4 20:23 wp-settings.php
-rw-r--r-- 1 root root 8.1K Apr 4 20:23 wp-mail.php
-rw-r--r-- 1 root root 33K Apr 4 20:23 wp-login.php
-rw-r--r-- 1 root root 2.7K Apr 4 20:23 wp-load.php
-rw-r--r-- 1 root root 2.4K Apr 4 20:23 wp-links-opml.php
-rw-r--r-- 1 root root 2.9K Apr 4 20:23 wp-cron.php
-rw-r--r-- 1 root root 2.7K Apr 4 20:23 wp-config-sample.php
-rw-r--r-- 1 root root 4.9K Apr 4 20:23 wp-comments-post.php
-rw-r--r-- 1 root root 271 Apr 4 20:23 wp-blog-header.php
-rw-r--r-- 1 root root 4.9K Apr 4 20:23 wp-activate.php
-rw-r--r-- 1 root root 7.1K Apr 4 20:23 readme.html
-rw-r--r-- 1 root root 20K Apr 4 20:23 license.txt
-rw-r--r-- 1 root root 418 Apr 4 20:23 index.php
drwxr-xr-x 12 root root 4.0K Jun 6 18:17 wp-includes
drwxr-xr-x 6 www-data www-data 4.0K Jun 6 18:17 wp-content
drwxr-xr-x 5 root root 4.0K Jun 6 18:17 .
drwxr-xr-x 9 root root 4.0K Jun 6 18:17 wp-admin
drwxr-xr-x 5 root root 4.0K Jun 6 18:17 ..
-rw-r--r-- 1 root root 3.5K Jun 6 19:03 wp-config.php
就像我在其中一条评论中所说的那样,我有另一个网站,SiteA 完全镜像到 SiteBroken 的配置,我很困惑为什么一个网站可以工作,而另一个网站 SiteBroken 却收到 403 错误,现在又收到 404 错误。
The requested URL /foo/ was not found on this server.
我一直在利用这些问题 https://askubuntu.com/questions/448944/where-to-place-my-local-website-starting-with-the-2-4-7-version-of-apache2和 https://stackoverflow.com/questions/6959189/apache-virtualhost-403-forbidden
我也简要安装了 nginx 并遇到了类似的问题,我认为 nginx 无法读取我的 php 文件?
答案1
将所有权更改为 www-data:www-data,并对托管内容的文件夹具有 r/w 权限,将允许 httpd 进程写入此文件夹,这取决于应用程序的复杂性及其安全性,可能会让黑客有办法用他或她自己选择的东西覆盖合法代码。
可能的问题是您需要将执行位添加到父文件夹并更改组:
chmod g=rx /var/www/SiteA
chown root:www-data /var/www/SiteA
chmod g=rx /var/www/SiteA/public_html
chown root:www-data /var/www/SiteA/public_html
如果没有执行位,进程就无法进入文件夹来读取文件,即使它拥有这些文件。
答案2
尝试配置你的 http-xampp
您会在那里找到这段代码:
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
尝试用这个来改变它:
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Require local
Require ip 192.120.203 // ip address of another pc or I would say the start of the ipaddress .
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
当我遇到该错误时,此方法对我有用。希望它对你也有用。
答案3
将所有权更改为www-data
而不是 root。您可以chown
这样做:
$ sudo chown -R www-data:www-data /var/www/SiteA/public_html
这将使 成为www-data
下所有文件/目录的所有者public_html
。
答案4
尝试将其放入你的 VirtualHost 中:
<Directory /var/www/SiteBroken/public_html/>
Require all granted
</Directory>
通常,将整个 WordPress 安装归 www-data 所有(即使是为了测试)是非常糟糕的做法。这将允许 Apache 进程将文件写入目录树中的任何位置,包括 PHP 文件。仅在过去 3 个月内,我就遇到过十几个网站以这种方式遭到黑客攻击。攻击者可以安装任何他们想要的东西 - 后门 shell、垃圾邮件机器人等等。他们还可以读取包含所有数据库凭据的 wp-config.php 文件。这也可能导致攻击者浏览其他网站目录(即 SiteA)并获得对该数据库的完全访问权限。
不确定上面的“要求全部授予”是否有帮助,但我知道 Apache 2.4 与 2.2 的安全机制不同,这在过去对我有帮助。