问题
Following is my virtual host in /etc/apache2/sites-available:
<VirtualHost *:80>
DocumentRoot "/var/www/roomstays/public"
ServerName roomstays
#This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/var/www/roomstays/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Also it enabled on /etc/apache2/sites-enabled folder
And following is my host file:
127.0.0.1 localhost
127.0.0.1 roomstays
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
I configured my site in var/www/roomstays. But when I entered roomstays on it not opening the site and showing this message :
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
What's wrong with virtual host.
回答1:
Three things to check:
1. Sites enabled
Make sure your virtual host file is in /etc/apache2/sites-enabled.
2. NameVirtualHost
Make sure you have this somewhere in the apache config:
NameVirtualHost *:80
I have it in /etc/apache2/ports.conf (can't remember if thats the standard on Ubuntu)
3. Remove default virtual host
If none of the above works, you can rename your virtual host to something like /etc/apache2/sites-enabled/000000-myhost. This will ensure your virtual host file is loaded first. Alternatively remove /etc/apache2/sites-enabled/000-default
Remember to restart apache after each change...
回答2:
How to set up virtual host for Zend Project:
Create project(folder) in location /var/www/ named 'roomstays'
Put in file /etc/hosts line:
127.0.0.1 roomstays.test
Create file in /etc/apache2/sites-available/ named "roomstays.conf" and put in it:
<VirtualHost *:80>
ServerName 127.0.0.1
ServerAlias roomstays.test
DocumentRoot /var/www/roomstays/public/
SetEnv APPLICATION_ENV "development"
<Directory /var/www/roomstays/public/>
Options All
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
Copy that file 'roomstays.conf' to location /etc/apache2/sites-enabled/
Restart apache, open browser and enter "roomstays.test" and that's work for me.
回答3:
is it not conflicting with localhost? try assigning a different IP address like
127.0.0.2
and also make sure you have added a directory with the alias name in to the apache log files directory
Hope it helps!
回答4:
This is what I did to fix this problem. Copy the virtualhost file in etc/apache2/sites-available and paste it into etc/apache2/sites-enabled. Go to your browser and refresh and you would see it work
回答5:
<VirtualHost *:80>
ServerName overstock.local
DocumentRoot "C:\xampp\htdocs\overstock"
<Directory "C:\xampp\htdocs\overstock">
AllowOverride All
</Directory>
</VirtualHost>
Then change htaccess to
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /overstock/
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]
回答6:
Be sure that # Virtual hosts line is active in your httpd.conf file.
Generally, it places under: /etc/apache2/httpd.conf
To edit the file you need root permission, so:
sudo vim /etc/apache2/httpd.conf
Uncomment the line
Include /private/etc/apache2/extra/httpd-vhosts.conf
Save file ESC + :wq + Enter
Restart your apache
来源:https://stackoverflow.com/questions/11259414/virtual-host-not-working-in-zend-framework