简体   繁体   中英

How to get a virtual host to work in OS X Lion?

I'm trying to set up a virtual host on my Mac OS X 10.7 Installation. I'm using VirtualHostX to manage my /etc/hosts and httpd-vhosts.conf file. Currently, my httpd-vhosts.conf file looks like this:

NameVirtualHost *:80

<Directory "/Users/yuval/Sites/mysite/">
Allow From All
AllowOverride All
</Directory>
<VirtualHost *:80>
    ServerName "mysite.dev"
    DocumentRoot "/Users/yuval/Sites/mysite"
</VirtualHost>

and my /etc/hosts files has this in it:

# VHX START
127.0.0.1 mysite.dev
fe80::1%lo0 mysite.dev
# VHX STOP

I activated Web Sharing under System preferences, and I know apache is running. However, when I navigate to either 127.0.0.1 or to mysite.dev, I get the following:

Forbidden

You don't have permission to access / on this server.

My permissions on /Users/yuval/Sites/mysite are 755. Trying to change them to 777 didn't help either. Note that this is happening with any folder I choose -- I do not have an .htaccess file in /Users/yuval/Sites/mysite.

Update : Checking the apache error, these are the logs that appear:

[Fri Dec 09 17:59:27 2011] [error] [client 127.0.0.1] (13)Permission denied:
    access to / denied
[Fri Dec 09 17:59:27 2011] [error] [client 127.0.0.1] (13)Permission denied:
    access to /favicon.ico denied

It seems pretty obvious that the vhosts + hosts code is doing its job in actually determining that the address exists, but for some reason this isn't working. Any ideas?

Make sure an index.html file is in the /Users/yuval/Sites/mysite/ directory.

OR enable directory indexing:

<Directory "/Users/yuval/Sites/mysite/">
  Options +Indexes
  Allow From All
  AllowOverride All
</Directory>

You can also set the DirectoryIndex option to look for default files other than index.html : http://httpd.apache.org/docs/current/mod/mod_dir.html

Edit

Saw your error message - this doesn't look like a directory index problem.

Try chmod 755 on the /Users/yuval directory as mentioned in this ServerFault answer: https://stackoverflow.com/a/1241319/212700

Also check for any .htaccess files in the /Users/yuval/Sites/ directory as Apache will check those as well.

The only thing I had to do was re-point to my custom vhost directory (and restart apache.)

I tried to point to ~/Sites/vhosts instead of /Users/[Username]/Sites/vhosts where I keep all my .conf files, so there was a configuration error. I was looking for the apache logs and learned from the apache docs about httpd -S which told me exactly where the configuration problems were.

Lots of misinformation in blogs on the net so Im posting this here for apache noobs like me.

httpd -S
# fix the issues
sudo apachectl restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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