温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

apache配置多个站点

发布时间:2020-06-16 18:44:37 来源:网络 阅读:174 作者:邹君安 栏目:网络安全

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

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

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

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

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

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

apache配置多个站点

注意把记录类型修改为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

 

修改配置文件代码如下:

apache配置多个站点

# 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 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

apache配置多个站点

保存退出到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配置多个站点

apache配置多个站点

 


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI