测试服务器:阿里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.comServerAdmin 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
第四步:进入管理控制台解析域名
点击 “解析“;
点击 “添加解析”
写入要添加的域名,解析到你的ip
最后一步:重启服务器
还有一步不要忘了,添加文件夹 (我的是wechat)
将项目放入文件夹 在浏览器输入自己的子域名,就可以访问了,要设定多个,方法重复,本人内测可用,如有不合之处,多多指教。