Apache-2.2
Apache 虛擬主機在 Vagrant 框中被忽略
我遇到的問題是,當我從主機訪問**http://d7.subdomain.example.org**時,它會將我帶到預設的 apache It Works頁面。我在一個帶有虛擬盒提供程序的 Ubuntu 12.04 Vagrant 盒子的 Mac 主機上。
sudo a2ensite d7.subdomain.example.org
我已經檢查了 sites-enabled/ 並且在執行命令後該站點確實出現在那裡。如果我去**http://d7.subdomain.example.org/drupal/site-docroot**它會把我帶到正確的地方。好像它一起忽略了我的虛擬主機。我的流浪文件:
# -*- 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 me@example.com 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>
也許您的 default-000.conf 文件弄亂了您的虛擬主機配置。
執行
apache2ctl -S
以在您的伺服器上啟用完整的虛擬主機列表。
您可以通過執行以下命令為您的項目創建虛擬主機配置文件:
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
並使用站點名稱添加您的 localhost ip,例如:
127.0.0.1 your_site_name
現在您可以在瀏覽器中輸入您的站點 url 來測試您的項目: http://your_site_name/
就是這樣 :)