Apache虚拟主机配置

24 篇文章 0 订阅
8 篇文章 0 订阅

 

测试服务器:阿里ECS服务器  镜像:ubuntu16.04.1

第一步:新增站点配置文件
在 /etc/apache2/sites-available 目录中中建立站点配置文件 wechat.conf
进入虚拟主机配置文件夹

cd /etc/apache2/sites-available/

复制默认的虚拟主机配置文件

cp 000-default.conf wechat.conf

编辑这配置文件

vi wechat.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.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

…………后面的不需要动…………

将红色部分的#去掉,然后将后面的网址改为自己想要的域名

如果需要修改路径,就绿色的部分就是项目的目录,根据自己实际情况进行指定

第二步:在 sites-enabled 目录下建立符号链接 ->sites-available

cd /etc/apache2/sites-enabled

建立对应的软链接

ln -s /etc/apache2/sites-available/wechat.conf /etc/apache2/sites-enabled/wechat.conf

第三步:修改 /etc/hosts 文件

打开查看 /etc/hosts 文件,在后面加入如下绿色部分代码

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.0.1 localhost
127.0.0.1 www.xxx.com

保存,退出,重启apache

/etc/init.d/apache2 restart

第四步:进入管理控制台解析域名

点击  “解析“;

143409_EsbZ_3578722.png

点击  “添加解析”

143529_bDdo_3578722.png

写入要添加的域名,解析到你的ip

143611_Gvfm_3578722.png

最后一步:重启服务器

143832_W1SD_3578722.png

还有一步不要忘了,添加文件夹 (我的是wechat)

143949_3bPC_3578722.png

将项目放入文件夹  在浏览器输入自己的子域名,就可以访问了,要设定多个,方法重复,本人内测可用,如有不合之处,多多指教。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值