即使使用与其他域一起使用的 DocumentRoot,Apache 也会导致 403 被禁止

Apache causes 403 forbidden even when using DocumentRoot that is working with other domain

wget http://maydomain.example

--2017-04-06 18:21:12--  https://mydomain.example
Resolving mydomain.example (mydomain.example)... IP
Connecting to mydomain.example (mydomain.example)|IP|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2017-04-06 18:21:12 ERROR 403: Forbidden.

但是其他域(在 http://OTHER.example)正在工作,所以我将 DocumentRoot 更改为 OTHER 并且(在重新启动 apache2 之后)错误是一样的!

<VirtualHost *:80>

    ServerAdmin suporte@mydomain.example
    ServerName mydomain.example
    ServerAlias www.mydomain.example
    DocumentRoot /var/www/html/OTHER.example

   # DocumentRoot /var/www/html/mydomain.example

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

#?? Require all granted
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.oficial.news [OR]
RewriteCond %{SERVER_NAME} =oficial.news
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

文件 /etc/apache2/sites-available/mydomain.example.conf/etc/apache2/sites-available/OTHER.example.conf 仅通过文件名和域名区别到其配置中。


注释

可能是...重写或 .access 在父文件夹?

more /var/www/html/.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*)  [L]
RewriteRule ^(.*\.php)$  [L]
RewriteRule . index.php [L]

我注意到您正在使用一些 Debian 衍生版本(可能是 Ubuntu 16.04)来为您的开发环境工作。我已经做过很多次了。

导致您的错误的原因可能是 var/www/html 文件夹是 "rooted"。这意味着,root 拥有它,而 Apache(www 数据用户)没有足够的权限来访问该内容。有几种解决方案。您可以选择最适合您的需求。我先post我喜欢的:

  1. 使用虚拟主机: 在 localhost 中工作可能对某些人有好处。我更喜欢使用以 .dev 结尾的虚拟主机。然后,我将文档根目录指向我拥有的文件夹项目,比本地主机更容易访问。我created a script可以轻松做到这一切。

  2. 更改 /var/www/html 的权限: 将该文件夹更改为 www-data 用户和 www-group 的文件夹,并对其进行 chmod 777 . 警告:确保将其上传到生产服务器时权限正常。

  3. 将 Apache 用户更改为 root: 在所有这些中,这是我最不推荐的,但它有效。

这是虚拟主机的配置...看到Rewrite*行,我删除了所有,

# REMOVED THIS:
# RewriteEngine on
# RewriteCond %{SERVER_NAME} =www.oficial.news [OR]
# RewriteCond %{SERVER_NAME} =oficial.news   
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

现在正在工作 (!)。

感谢@Nomad 和@MatíasNavarroCarter 提供的线索和清单。