我遇到的问题是,当我访问http://d7.subdomain.example.org从我的主机,它会带我到默认的 apache有用页面。我在一台 Mac 主机上,装有带 virtualbox 提供程序的 Ubuntu 12.04 Vagrant 盒。
我检查了 sites-enabled/,运行命令后该网站确实出现在那里sudo a2ensite d7.subdomain.example.org
。如果我去http://d7.subdomain.example.org/drupal/site-docroot它会带我到正确的地方。它似乎完全忽略了我的虚拟主机。
我的Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.vm.define "drupal" do |node|
node.vm.hostname = "d7.subdomain.example.org"
node.vm.network :private_network, ip: "172.22.22.26"
node.hostmanager.aliases = [ "www.d7.subdomain.example.org" ]
end
config.vm.provision :hostmanager
config.vm.synced_folder "./drupal", "/var/www/html/drupal/", type: "nfs"
config.vm.provider "virtualbox" do |vm|
vm.customize ["modifyvm", :id, "--memory", "2048"]
vm.customize ["modifyvm", :id, "--cpus", "1"]
vm.customize ["modifyvm", :id, "--cpuexecutioncap", "85"]
end
config.vm.provision "shell" do |script|
script.path = "provisioner.sh"
end
end
我的配置脚本:
#! /bin/bash
sudo apt-get update -y
sudo apt-get install apache2 -y
sudo apt-get install debconf-utils -y
debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw"
sudo apt-get install mysql-server -y
mysql -uroot -prootpw -e "CREATE DATABASE mydbford7;
USE mydbford7;
SOURCE /var/www/html/drupal/setup/dump.sql;
CREATE USER 'vagrant'@'localhost' IDENTIFIED BY 'vagrant';
GRANT ALL PRIVILEGES ON mydbford7.* TO 'vagrant'@'localhost' IDENTIFIED BY 'vagrant';
FLUSH PRIVILEGES;"
sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
sudo service mysql restart
sudo apt-get install python-software-properties build-essential -y
sudo add-apt-repository ppa:ondrej/php5 -y
sudo apt-get install php5-common php5-dev libapache2-mod-php5 php5-cli php5-fpm -y
sudo apt-get install curl php5-curl php5-gd php5-mcrypt php5-mysql -y
a2enmod rewrite
sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/apache2/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/apache2/php.ini
cp /var/www/html/drupal/setup/myd7_vhost /etc/apache2/sites-available/d7.subdomain.example.org.conf
sudo a2ensite d7.subdomain.example.org
sudo service apache2 restart
sudo service apache2 reload
虚拟主机文件:
<VirtualHost *:80>
ServerName d7.subdomain.example.org
ServerAdmin [email protected]
DocumentRoot "/var/www/html/drupal/site-docroot"
<Directory "/var/www/html/drupal/site-docroot/">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "/var/log/apache2/error_log"
TransferLog "/var/log/apache2/access_log"
</VirtualHost>
答案1
也许您的 default-000.conf 文件弄乱了您的虚拟主机配置。
运行apache2ctl -S
以获取在您的服务器上启用的虚拟主机的完整列表。
答案2
您可以通过运行以下命令为您的项目创建虚拟主机配置文件:
vhost="<VirtualHost *:80>
ServerName site_name.local
DocumentRoot /path/to/project
<Directory /path/to/project>
Order allow,deny
Allow from all
Require all granted
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/sitename_error.log
CustomLog ${APACHE_LOG_DIR}/sitename_access.log combined
</VirtualHost>"
echo "$vhost" | sudo tee /etc/apache2/sites-available/site_name.local.conf
sudo a2ensite site_name.local.conf
service apache2 restart
然后编辑你的主机文件
sudo nano /etc/hosts
并添加你的本地主机 ip 和站点名称,例如:
127.0.0.1 your_site_name
现在,您可以通过输入网站网址在浏览器中测试您的项目: http://您的网站名称/
就是这样 :)