msgbartop
better late than never
msgbarbottom

Jun 04 ubuntu下apache虚拟主机的配置+开启rewrite模块 -_-

这博客是在win下写的,想当初刚放到网上,因为大小写的问题折腾了不少时间,趁着装了ubuntu,把博客也移到下面,减少网上的折腾时间。

ub下是新装的环境,首先是木有虚拟主机,古狗大叔倒是有不少方法,却是完全不相同的,- -+,挑了一个最终成功的方法。就拿我在本地的虚拟主机来说明吧。

我博客存放的目录是/var/www/blog/blog/

最后访问的域名是blog.localhost

使用的方法感觉跟win下差不多

root@localhost:~$ sudo gedit /etc/hosts

在hosts中加入一行:127.0.0.1    blog.localhost

root@localhost:~$ sudo gedit /etc/apache2/sites-available/default

添加虚拟主机

把原有的内容拷贝,在下面粘贴,改几行

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName blog.localhost //这行是要添加的
DocumentRoot /var/www/blog/blog/ //这行是要改的
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/blog/blog> //这行也是要改的
Options Indexes FollowSymLinks MultiViews
AllowOverride All  //这行也要改,原来是None,不改的话,下面的rewrite就不生效了。
Order allow,deny
allow from all
</Directory>

…… //这下面就没改了

root@localhost:~$ sudo /etc/init.d/apache2 restart

重启apache,blog.localhost就有用了。

下面是开启rewrite模块,比较简单

root@localhost:~$ sudo a2enmod rewrite

再重启下apache,就好用了,上面的default文件的AllowOverride None要改成All,才有效。MS是因为如果是None,会忽略.htaccess文件。

确实没啥技术含量,不断折腾。



Leave a Comment




*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word