知识准备:
区别于Windows 下apache,配置文件通常只有一个,就是httpd.conf。
Linux下 Apache的配置文件是 /etc/apache2/apache2.conf,Apache在启动时会自动读取这个文件的配置信息。而其他的一些配置文件,如 httpd.conf等,则是通过Include指令包含进来。
在apache2.conf里有sites-enabled目录,而在 /etc/apache2下还有一个sites-available目录,其实,这里面才是真正的配置文件,而sites- enabled目录存放的只是一些指向这里的文件的符号链接,你可以用ls /etc/apache2/sites-enabled/来证实一下。
所以,如果apache上配置了多个虚拟主机,每个虚拟主机的配置文件都放在 sites-available下,那么对于虚拟主机的停用、启用就非常方便了:当在sites-enabled下建立一个指向某个虚拟主机配置文件的链 接时,就启用了它;如果要关闭某个虚拟主机的话,只需删除相应的链接即可,根本不用去改配置文件。
了解这些以后,就开始配置apache之旅吧~
1. copy /etc/apache2/sites-avaliable/default , 命名为 kris
2.修改配置文件:kris
[html] view plaincopy
-
<VirtualHost *:80>
-
ServerAdmin webmaster@localhost
-
-
ServerName kris
-
-
DocumentRoot /var/www/kris
-
<Directory /var/www/kris>
-
Options Indexes FollowSymLinks MultiViews
-
AllowOverride None
-
Order allow,deny
-
allow from all
-
</Directory>
-
-
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
-
<Directory "/usr/lib/cgi-bin">
-
AllowOverride None
-
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
-
Order allow,deny
-
Allow from all
-
</Directory>
-
-
ErrorLog ${APACHE_LOG_DIR}/error.log
-
-
# Possible values include: debug, info, notice, warn, error, crit,
-
# alert, emerg.
-
LogLevel warn
<VirtualHost *:80>
ServerAdmin xxx@xxx.com
ServerName repo.com
ServerAlias *.repo.com
DocumentRoot "/mnt/www/revo/public/"
DirectoryIndex index.php
<Directory "/mnt/www/revo/public">
Options -Indexes
Order Deny,Allow
allow from all
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</Directory>
ErrorLog ${APACHE_LOG_DIR}/revo-error.log
CustomLog ${APACHE_LOG_DIR}/revo-access.log combined
</VirtualHost>
~
前提是你已经在 /var/www 下已经kris目录
3. 建立链接文件:
sudo ln -s /etc/apache2/sites-available/kris /etc/apache2/sites-enabled/kris
4. 重启apache 服务器
sudo /etc/init.d/apache2 restart
5. 客户端(如windows 7)修改hosts
添加
192.168.17.128 kris
注释:192.168.17.128是你的ubuntu虚拟机的ip地址
想要在加一个目录只要重复上述步骤,然后在hosts文件中加入
192.168.17.128 extend 绑定一下就可以了,是不是很简单呢,好了现在赶紧去搞吧
Internet 选线--连接 -- 添加例外(这一步不是必须,看自己的实际情况吧 )
6. 访问
在浏览器中输入kris 访问成功