apache 配置 VirtualDocumentRoot
apache config VirtualDocumentRoot
我的httpd-vhosts.conf
中有这个配置:
<Directory "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites/_localhost"
UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites/%2"
ServerName sites.dev
ServerAlias www.*.dev
ServerAlias www.*.dev.*.xip.io
UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites/%1"
ServerName sites.dev
ServerAlias *.dev
ServerAlias *.dev.*.xip.io
UseCanonicalName Off
</Virtualhost>
当我尝试访问我的网站时,我收到一个 403 禁止访问的页面。
当我查看 apache 错误日志时,我看到了这个:
[Sun Jun 26 12:09:12.310868 2016] [core:error] [pid 1272] (13)Permission denied: [client 127.0.0.1:50110] AH00035: access to /favicon.ico denied (filesystem path '/Users/username/Library/Mobile Documents') because search permissions are missing on a component of the path, referer: http://site.dev/
我不完全理解为什么路径停在 Mobile Documents
。所有文件夹都存在,我的根目录中确实有一个 index.php
文件,也没有其他解释 403 错误的原因。
我在这里错过了什么?我该如何解决这个问题?
啊,我的问题解决了。可能不是最好的方法,但它确实有效,所以如果有人有更好的想法,请分享。
我的解决方案:
我将 apache 的用户和组 运行 从 _www 更改为我自己的用户名和组。
我使用了这个解决方案:
https://coolestguidesontheplanet.com/forbidden-403-you-dont-have-permission-to-access-username-on-this-server/
Changing The Apache Web User
One of the frustrations of using the Users/username/Sites folder is
the permissions issues with things like updates and authentication.
This is because the default webserver user which runs httpd
is known
as _www
, which will not be the user in your local account. If your
machine is only in use by you and the webserver will run only under
your account then you can change the user.
Change this back in /etc/apache2/httpd.conf
Just change it to your username and group, group will be staff and
restart Apache
sudo apachectl restart
我的httpd-vhosts.conf
中有这个配置:
<Directory "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites/_localhost"
UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites/%2"
ServerName sites.dev
ServerAlias www.*.dev
ServerAlias www.*.dev.*.xip.io
UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/uername/Library/Mobile Documents/com~apple~CloudDocs/Sites/%1"
ServerName sites.dev
ServerAlias *.dev
ServerAlias *.dev.*.xip.io
UseCanonicalName Off
</Virtualhost>
当我尝试访问我的网站时,我收到一个 403 禁止访问的页面。 当我查看 apache 错误日志时,我看到了这个:
[Sun Jun 26 12:09:12.310868 2016] [core:error] [pid 1272] (13)Permission denied: [client 127.0.0.1:50110] AH00035: access to /favicon.ico denied (filesystem path '/Users/username/Library/Mobile Documents') because search permissions are missing on a component of the path, referer: http://site.dev/
我不完全理解为什么路径停在 Mobile Documents
。所有文件夹都存在,我的根目录中确实有一个 index.php
文件,也没有其他解释 403 错误的原因。
我在这里错过了什么?我该如何解决这个问题?
啊,我的问题解决了。可能不是最好的方法,但它确实有效,所以如果有人有更好的想法,请分享。 我的解决方案: 我将 apache 的用户和组 运行 从 _www 更改为我自己的用户名和组。 我使用了这个解决方案: https://coolestguidesontheplanet.com/forbidden-403-you-dont-have-permission-to-access-username-on-this-server/
Changing The Apache Web User
One of the frustrations of using the Users/username/Sites folder is the permissions issues with things like updates and authentication.
This is because the default webserver user which runs
httpd
is known as_www
, which will not be the user in your local account. If your machine is only in use by you and the webserver will run only under your account then you can change the user.Change this back in
/etc/apache2/httpd.conf
Just change it to your username and group, group will be staff and restart Apache
sudo apachectl restart