简体   繁体   English

与Yosemite的Apache localhost 403错误

[英]Apache localhost 403 error with Yosemite

I've just installed Mac OS X Yosemite fresh. 我刚刚安装了Mac OS X Yosemite。 I configured Apache and chmodded "users/user/Sites" to 755. When I hit localhost I receive a 403 Forbidden "You don't have permission to access / on this server" . 我将Apache和chmodded“users / user / Sites”配置为755.当我点击localhost时,我收到403 Forbidden "You don't have permission to access / on this server" The same thing occurs with any other sites I add to my hosts file. 我添加到主机文件的任何其他站点都会出现同样的情况。

I tried configuring user directories following help from this post . 我尝试按照这篇文章的帮助配置用户目录。 The guys on this MacRumors thread know there is an Apache issue, but didn't offer a lot of suggestions. 这个MacRumors线程上的人知道有一个Apache问题,但没有提供很多建议。

My directory permissions look like this 我的目录权限如下所示

drwxr-xr-x  29 root             wheel  1054 Aug 11 07:30 /
drwxr-xr-x   6 root             admin   204 Aug 11 07:29 /Users/
drwxr-xr-x+ 26 zachshallbetter  staff   884 Aug 11 11:57 /Users/zachshallbetter/
 0: group:everyone deny delete
drwxr-xr-x   5 zachshallbetter  staff   170 Aug 11 10:16 /Users/zachshallbetter/Sites

Can anyone offer any suggestions or help? 有人可以提供任何建议或帮助吗? Here are links to my hosts and httpd.conf files and error logs for reference. 以下是我的主机httpd.conf文件的链接以及错误日志以供参考。

You do NOT want to open up the entirety of your hard drive to the web server process. 您不希望将整个硬盘驱动器打开到Web服务器进程。 In fact, lines 215-217 of httpd.conf say: 实际上, httpd.conf第215-217行说:

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

Apache 2.4 (OSX 10.10 Yosemite) has a different structure from Apache 2.2 (OSX 10.9) for the Directory directive in Module mod_authz_core . Apache 2.4(OSX 10.10 Yosemite) 与模块mod_authz_core中Directory指令具有不同于Apache 2.2(OSX 10.9)的结构。

EDIT: If you are setting up Apache from the START, please follow this instruction set to setup apache and php on OSX 10.10 Yosemite. 编辑: 如果您从START设置Apache,请按照此指令集在OSX 10.10 Yosemite上设置apache和php。

Assuming you have mod_userdir.so enabled already, your problem is within your user .conf file ( /etc/apache2/users/username.conf ), edit (or add) the following. 假设您已经启用了mod_userdir.so ,则问题出在您的用户.conf文件( /etc/apache2/users/username.conf )中,编辑(或添加)以下内容。

Apache 2.2: Apache 2.2:

<Directory "/Users/jnovack/Sites/">
  Options Indexes MultiViews
  AllowOverride All
  # OSX 10.9 / Apache 2.2
  Order from deny, allow
</Directory>

Apache 2.4 Apache 2.4

<Directory "/Users/jnovack/Sites/">
  Options Indexes MultiViews
  AllowOverride All
  # OSX 10.10 / Apache 2.4
  Require all granted
</Directory>

Edit the file: /private/etc/apache2/httpd.conf 编辑文件:/private/etc/apache2/httpd.conf

on line 250 (in Yosemite) change: 在250号线(在优胜美地)改变:

Options FollowSymLinks Multiviews

to: 至:

Options FollowSymLinks Multiviews Indexes

then in the Terminal run: 然后在终端运行:

sudo apachectl restart

This might be very late answer but i did followed most of Stack Overflow solutions, None of them helped me for various reasons. 这可能是非常晚的答案,但我确实遵循了大部分的Stack Overflow解决方案,由于各种原因,他们都没有帮助我。 So i did reset my device as a fresh Yosemite OS to get this localhost working on Mac Yosemite (with Symlinks too), 所以我确实将我的设备重置为一个新的Yosemite操作系统,让这个本地主机在Mac Yosemite上运行(也有Symlinks),

Steps I did exactly : 我完成的步骤:

sudo nano /etc/apache2/httpd.conf

Uncomment the following lines: 取消注释以下行:

#LoadModule php5_module libexec/apache2/libphp5.so
to
LoadModule php5_module libexec/apache2/libphp5.so


#LoadModule userdir_module libexec/apache2/mod_userdir.so
to
LoadModule userdir_module libexec/apache2/mod_userdir.so


#Include /private/etc/apache2/extra/httpd-userdir.conf
to
Include /private/etc/apache2/extra/httpd-userdir.conf

Save and Exit (Ctrl+X press Enter and press Y and enter again) 保存并退出(Ctrl + X按Enter键并按Y键再次输入)

sudo nano /etc/apache2/extra/httpd-userdir.conf

and uncomment the following line at line 16: 并在第16行取消注释以下行:

#Include /private/etc/apache2/users/*.conf
to
Include /private/etc/apache2/users/*.conf

Save and Exit (Ctrl+X press Enter and press Y and enter again). 保存并退出(Ctrl + X按Enter键并按Y键再次输入)。

Now go to apache Users folder to check your configuration file exist or not 现在转到apache Users文件夹检查配置文件是否存在

cd /etc/apache2/users/

if you do not have configuration file in this folder, create one by 如果此文件夹中没有配置文件,请创建一个

sudo nano /etc/apache2/users/<**YOUR USERNAME**>.conf

Replace <YOUR USERNAME> with the name of your machine (type whoami in terminal and enter that name). <YOUR USERNAME>替换为您的计算机名称(在终端中键入whoami并输入该名称)。

after creating .conf file , copy below lines into that file 创建.conf文件后,将下面的行复制到该文件中

<Directory "/Users/<YOUR USERNAME>/Sites/">
    AddLanguage en .en
    LanguagePriority en fr de
    ForceLanguagePriority Fallback
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from localhost
     Require all granted
</Directory>

save and Exit 保存并退出

Now restart your apache 现在重启你的apache

sudo apachectl restart

Now go to your browser and type localhost, it should work as expected, 现在转到您的浏览器并键入localhost,它应该按预期工作,

Just as a Note: if it does not work even after try restarting your computer 就像一个注意:如果尝试重新启动计算机后它仍然无效

create index.html as exactly index.html.en that you should find here: 将index.html创建为index.html.en,您可以在此处找到:

open /Library/Webserver/Documents/

right click on index.html.en and duplicate it to index.html leaving original as it is 右键单击index.html.en并将其复制到index.html,保留原始状态

try again in browser and if you have success, you can delete the duplicated file 在浏览器中再试一次,如果成功,则可以删除重复的文件

Just to be clear, leave the original file index.html.en where it is, untouched and unharmed throughout this step. 为了清楚起见,请将原始文件index.html.en保留在原始文件中,在此步骤中不受影响且不受伤害。

Not sure why I had to take this mysterious detour - probably something local to my machine, but if you're having trouble after following the guide above, see if it helps. 不知道为什么我不得不采取这个神秘的绕道 - 可能是我的机器本地的东西,但如果你按照上面的指南后遇到麻烦,看看它是否有帮助。

SymLinks : SymLinks

if you have success, in Browser you should see 如果你有成功,你应该在浏览器中看到

It works!

Now create symlink to any your project. 现在为您的任何项目创建符号链接。

ln -s <Path_to_your_Project(index_file)> <Path_to_webroot>

For example if you have project folder in your Documents folder ,then point webroot to your index file by 例如,如果您的Documents文件夹中有项目文件夹,则将webroot指向您的索引文件

ln -s /Users/<YOUR USERNAME>/Documents/project/ /Library/Webserver/documents/projectlink 

you might need permission to create symlink (Use above command with Sudo) 您可能需要创建符号链接的权限(使用上面的命令与Sudo)

Configure apache to follow symlinks ( Thanks to tomvon, i do not enough points to vote you) 配置apache以遵循符号链接(感谢tomvon,我没有足够的分数来投票给你)

sudo nano /private/etc/apache2/httpd.conf

on line 250 (in Yosemite) change: 在250号线(在优胜美地)改变:

Options FollowSymLinks Multiviews

to: 至:

Options FollowSymLinks Multiviews Indexes

then in the Terminal run: 然后在终端运行:

sudo apachectl restart

Now go to localhost/projectlink to see if your project index file shows here on browser. 现在转到localhost/projectlink以查看您的项目索引文件是否显示在浏览器上。

Happy Coding.. 快乐编码..

The advice in this article helped me. 本文中的建议对我有所帮助。

Specifically the "Yosemite Only" section: 特别是“Yosemite Only”部分:

First, there is a directive that helps secure your machine by denying access to the entire file system by default. 首先,有一个指令通过默认拒绝访问整个文件系统来帮助保护您的计算机。 I'll show you how to remove this directive, since I find that easier on a machine meant for development. 我将向您展示如何删除此指令,因为我发现在用于开发的机器上更容易。 The section of code runs from line 220 through 223. You can comment out (place '#' in front of each line) or just remove this section. 代码部分从第220行到第223行。您可以注释掉(在每行前面放置'#')或只删除此部分。

And the section is ... 那节是......

<Directory />
 AllowOverride none
 Require all denied
</Directory>

Note: 注意:

As others have followed up on this with more details, the method outlined above can be insecure. 正如其他人对此进行了详细介绍,上述方法可能不安全。

There are 2 possibility why your localhost is forbidden, first it may be because your apache setting is not correct and second, may be because you set vhost and you forget about set localhost too 有两种可能性为什么你的localhost被禁止,首先可能是因为你的apache设置不正确,其次可能是因为你设置了vhost而你忘记了设置localhost也是

  1. sudo nano /etc/apache2/extra/httpd-vhosts.conf
  2. Add this code 添加此代码

` `

<VirtualHost *:80>
     ServerName localhost
     DocumentRoot "/Users/username/Sites"
     <Directory "Users/username/Sites">
        Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all
     </Directory>
 </VirtualHost>  
  1. Save it and restart your apache 保存并重启你的apache

` `

sudo apachectl restart

it should be works :) 它应该是工作:)

Suggestions might focus on your own user specific conf in apache but by default this configuration might not be loaded at all. 建议可能会关注您自己在apache中的用户特定conf,但默认情况下可能根本不会加载此配置。

Edit the userdir module configuration: 编辑userdir模块配置:

sudo vi /etc/apache2/extra/httpd-userdir.conf sudo vi /etc/apache2/extra/httpd-userdir.conf

Uncomment the include of the user directory configuration files: 取消注释用户目录配置文件的包含:

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

Make sure you have a user directory configuration according our own username: 确保根据我们自己的用户名进行用户目录配置:

sudo vi /etc/apache2/users/.conf sudo vi /etc/apache2/users/.conf

Make sure you have good configuration for your home directory: 确保您的主目录配置良好:

DocumentRoot "/Users/<username>/Sites/" <Directory "/Users/<username>/Sites/"> AllowOverride All Options Indexes MultiViews FollowSymLinks Require all granted </Directory>

Restart apache (webserver) 重启apache(webserver)

sudo apachectl restart sudo apachectl重启

Check your site! 检查您的网站!

Just create the 'Sites' folder in your user folder. 只需在用户文件夹中创建“Sites”文件夹即可。 Go to

cd ~ cd~
mkdir 'Sites' mkdir'网站'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM