码迷,mamicode.com
首页 > Web开发 > 详细

apache配置多个站点

时间:2017-01-21 14:01:40      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:多个   地址   域名解析   als   following   微信公众号   src   disco   virtual   

序:这次项目主要是为了给微信客户端添加一个地址,在微信公众号里面添加一个可以访问的app下载页面,说起来很简单,但总不能为了这么小的一个网站新建一个web服务器吧!

现在开始配置,首先必须确认已经在Linux上搭建好了LAMP环境,并且有一个站点可以正常访问,以我的apache-ubuntu为例,默认目录是:/var/www/html/

来先明确这个新的站点该放在哪儿,我绝不建议继续放到默认目录下一个目录,应该放在www下面,我这么做的,

sudo mkdir /var/www/sunjob-app        //新建一个站点目录

没错,我的新小网站的目录就在这个sunjob-app下面吧

接下来先别着急去配置文件,去域名购买站点修改解析,我的是万网,添加域名解析,如图:

技术分享

注意把记录类型修改为cname,不是图中的A,记录就是域名前缀,默认是www,我修改成了app,那么最终访问时候的请求地址就是:app.ygdiy.com(注意前缀变了)

域名解析结束,保存!

回到ubuntu服务器,开始配置这个域名解析的新站点:

cd /etc/apache2/sites-available/            //进入可获取站点配置目录下

//vim新建并修改一个配置文件,我直接命名成了新站点,但注意后缀是.conf,因为在apache.conf中默认是include "*.conf"文件的

//而nginx中nginx.conf配置了“include sites-enable/*”所以所有文件都会被加载,apache只加载.conf后缀的

vim ./app.ygdiy.conf

 

修改配置文件代码如下:

# 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 requests 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 app.ygdiy.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/sunjob-app

    # 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

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combinedOptions Indexes FollowSymLinks MultiViews
         AllowOverride all
         Order allow,deny
         allow from all# 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

保存退出到bash中,把站点链接到enable中:

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

配置ok了,注意配置文件中,DocumentRoot 必须是存在并且可以访问的目录,因为新站点存放在这里头,被apache提供给用户访问

另外,servername,设置成刚刚解析的新域名名字,cname的那个,注意了哟

重启apache

sudo service apache2 restart

 

最后把新网站的文件拷贝到/var/www/sunjob-app/下,你们拷贝到自己命名配置的目录下即可,浏览器输入站点新域名即可访问了,最后献上我的效果图,晚安

技术分享

技术分享

 

apache配置多个站点

标签:多个   地址   域名解析   als   following   微信公众号   src   disco   virtual   

原文地址:http://www.cnblogs.com/devilyouwei/p/6336900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!