MacOS Dnsmasq High Sierra 403 禁止错误

MacOS Dnsmasq High Sierra 403 Forbidden error

我尝试使用干净的 macOS High Sierra 10.13.2 配置 dnsmasq

Apache 版本

Server version: Apache/2.4.28 (Unix)
Server built:   Oct  9 2017 19:54:20
apachectl configtest
Syntax OK

我曾经拥有它并且工作得很好。但我想我遗漏了一些东西,因为我在本地主机、127.0.0.1 和 home.test 或 anything.test

等任何项目上收到 403 禁止错误
Forbidden
You don't have permission to access / on this server.

我取消了必要文件的注释以使其正常工作:

httpd.conf

Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/httpd-userdir.conf
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule php7_module libexec/apache2/libphp7.so
User absolutkarlos
Group staff
ServerName localhost
Directory > AllowOverride None
Directory > Options FollowSymLinks Multiviews Indexes

dnsmasq.conf

address=/test/127.0.0.1

absolutkarlos.conf

Directory "/Users/absolutkarlos/DOC/www/sites/"
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted

httpd-userdir.conf

UserDir sites
Include /private/etc/apache2/users/*.conf

httpd-vhosts.conf

<Directory "/www">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>

<Virtualhost *:80>
VirtualDocumentRoott "/Users/absolutkarlos/DOC/www/home/wwwroot"
ServerName home.test
UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
VirtualDocumentRoot "/Users/absolutkarlos/DOC/www/sites/%1/wwwroot"
ServerName sites.test
ServerAlias *.test
UseCanonicalName Off
</Virtualhost>

error_log

AH01630: client denied by server configuration: /Users/absolutkarlos/DOC/www/home, referer: http://home.test/
AH01630: client denied by server configuration: /Users/absolutkarlos/DOC/www/home, referer: http://localhost/
AH01630: client denied by server configuration: /Users/absolutkarlos/DOC/www/home, referer: http://127.0.0.1/

任何 ping 都正常

ping

ping -c 1 home.test
PING home.test (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.035 ms

--- home.test ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.035/0.035/0.035/0.000 ms

如果您在使用 dnsmasq 时执行此操作(不是创建动态虚拟主机,而是将每个虚拟主机添加到您的 httpd-vhost 文件中),请确保在您的 httpd.conf 文件中,DocumentRoot 指令指向一个目录在您正在创建项目的那个上面。

即: /Users/MyUser/Projects/

  • 博客
  • 项目 2
  • 测试项目

在你的 httpd-vhosts.conf 文件中

<VirtualHost *:80>
    DocumentRoot "/Users/MyUser/Projects/blog"
    ServerName blog.test
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/MyUser/Projects/project2"
    ServerName project2.test
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/MyUser/Projects/testproject"
    ServerName testproject.test
</VirtualHost>

然后,在httpd.conf(大约第 248 行):

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Users/MyUser/Projects/"
<Directory "/Users/MyUser/Projects/">

如果您的项目不直接在 /Users/MyUser/Projects 下,Apache 将回退到您的系统访问指令,默认情况下拒绝访问(大约第 230 行):

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied
</Directory>