阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu Apache 虚拟主机配置

139次阅读
没有评论

共计 2901 个字符,预计需要花费 8 分钟才能阅读完成。

区别于 Windows 下 Apache,配置文件通常只有一个,就是 httpd.conf。

本机环境是通过 apt-get install xxx

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 下建立一个指向某个虚拟主机配置文件的链 接时,就启用了它;如果要关闭某个虚拟主机的话,只需删除相应的链接即可,根本不用去改配置文件。

1. sudo cp /etc/apache2/sites-avaliable/000-default.conf , 命名为 test.conf

2. 修改配置文件:test.conf

<VirtualHost *:80>

# The ServerName directive sets the request scheme, hostname and port that

# the server uses to identify itself. This is used when creating

# redirection URLs. In the context of virtual hosts, the ServerName

# specifies what hostname must appear in the request’s Host: header to

# match this virtual host. For the default virtual host (this file) this

# value is not decisive as it is used as a last resort host regardless.

# However, you must set it for any further virtual host explicitly.

ServerName www.test.com

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html/test/

ErrorLog /var/www/html/test/error.log

CustomLog /var/www/html/test/access.log combined

<Directory “/var/www/html/test”>

    Options FollowSymLinks

    DirectoryIndex index.php index.html index.htm

    AllowOverride All #注意这个地方的配置,会影响本地目录下的.htaccess 的启用

    Order deny,allow

    Allow from All

</Directory>

# Available loglevels: trace8, …, trace1, debug, info, notice, warn,

# error, crit, alert, emerg.

# It is also possible to configure the loglevel for particular

# modules, e.g.

#LogLevel info ssl:warn

# For most configuration files from conf-available/, which are

# enabled or disabled at a global level, it is possible to

# include a line for only one particular virtual host. For example the

# following line enables the CGI configuration for this host only

# after it has been globally disabled with “a2disconf”.

#Include conf-available/serve-cgi-bin.conf

</VirtualHost>

3. 建立链接文件:

sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/test.conf

或者:sudo a2ensite test.conf

4. 重启 apache 服务器

sudo /etc/init.d/apache2 restart

5. 修改 hosts(/etc/hosts)

添加 127.0.0.1 www.test.com

到这里基本就可正常访问了!

附:如果这里还需要对目录级的 URL 重写支持,继续往下:

1. 终端运行

sudo a2enmod

程序提示可供激活的模块名称,输入:rewrite

成功会提示 rewrite already load

 2. 修改 /etc/apache2/sites-enabled/test.conf (该链接指向的是站点配置文件)
把下的 AllowOverride 属性改为 All,保存。(上面我们已经配置为 All)

 3. 重新加载 apache

sudo /etc/init.d/apache2 restart

Ubuntu Server 14.04 安装 Web 服务器 (Linux+Apache+MySQL+PHP)  http://www.linuxidc.com/Linux/2015-06/119061.htm

Linux 下安装配置 PHP 环境 (Apache2)  http://www.linuxidc.com/Linux/2015-05/118062.htm

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

Apache 的详细介绍 :请点这里
Apache 的下载地址 :请点这里

更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-01/127828.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2901字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中