Ubuntu12.04LTS 配置虚拟站点(端口)

本文转载自https://zlizhe.com/archives/286

本人只是按照自己使用过程做了一些修改,未经允许不得转载!

本文是在Ubuntu 下搭建LAMP环境配置多个站点。过程如下:

1、搭建好了LAMP环境后我们在使用中发现,我们需要多个端口来配置不同的虚拟主机给不同的项目来使用。我们首先想到的就是修改 APACHE配置文件  一般为 httpd.conf 或 apache2.conf 等。

cd /etc/apache2

我们发现该目录下存在 apache2.conf 配置文件 使用VI编辑他

sudo vi apache2.conf

但在该配置文件中并未发现我们熟悉的默认80端口的配置。配置文件中这样几行引起了我们的注意。

# Include list of ports to listen on and which to use for name based vhosts

Include ports.conf

我们打开 ports.conf 文件进行查看

2、添加监听端口

sudo vi ports.conf

果然Ubuntu下的APACHE将配置文件分为了多个文件进行操作

NameVirtualHost *:80

Listen 80

Listen 801

下方是我们新添加的端口,保存并退出该文件

3、添加虚拟主机配置

cd /etc/apache2/sites-available

sudo cp default newname /*COPY一份默认配置*/

sudo vi newname /*编辑新文档*/

请注意我们修改了加黑位置的文字已配合新端口来使用

<VirtualHost *:801>

ServerAdmin webmaster@localhost

DocumentRoot <span style="color:#FF0000;">/var/www/myproject</span>

<Directory />

Options FollowSymLinks

AllowOverride all

</Directory>

<Directory  /var/www/myproject/>

Options Indexes FollowSymLinks MultiViews

AllowOverride all

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

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

从配置文件不难看出我们的虚拟主机 日志的存放位置

4、发布新站点

sudo ln -s /etc/apache2/sites-available/newname /etc/apache2/sites-enabled/001-default

创建好了新站点的配置文件,要让他们生效们还必须将配置文件软链接到 sites-enabled 文件夹中。

sudo a2ensite demo

sudo a2enmod rewrite

sudo /etc/init.d/apache2 restart

5、访问新站点

打开浏览器 访问  http://localhost:801 已经可以正常访问 了。说明配置正确!

重启APACHE2可能会出现如下错误。

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

解决步骤:

为了解决这个问题,你需要编辑下面这个httpd.conf文件,打开它并根据如下操作进行编辑:

sudo gedit /etc/apache2/httpd.conf

加入如下内容

ServerName localhost 重启APACHE2

sudo /etc/init.d/apache2 restart

重启成功。


注意事项:apache重写要开    haitaoxggyl文件的是否允许重写设置成all

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值