CentOS 7 Apache 绑定域名和网站
<p>CentOS 7 Apache 绑定域名和网站<br>适用场景<br>一台服务器,运行有多个网站,每个网站都希望用户直接通过二级域名来访问,而不是同一个域名通过子目录来访问</p><p>配置过程<br>确定自己的 Apache 服务器的管理文件<br>使用命令</p>
<p>$ httpd -V<br>1<br>来查看关于 httpd 的相关配置信息:</p>
<p>$ httpd -V<br>Server version: Apache/2.4.6 (CentOS)<br>Server built: Oct 19 2017 20:39:16<br>Server's Module Magic Number: 20120211:24<br>Server loaded:APR 1.4.8, APR-UTIL 1.5.2<br>Compiled using: APR 1.4.8, APR-UTIL 1.5.2<br>Architecture: 64-bit<br>Server MPM: prefork<br>threaded: no<br> forked: yes (variable process count)<br>Server compiled with....<br> -D APR_HAS_SENDFILE<br> -D APR_HAS_MMAP<br> -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)<br> -D APR_USE_SYSVSEM_SERIALIZE<br> -D APR_USE_PTHREAD_SERIALIZE<br> -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT<br> -D APR_HAS_OTHER_CHILD<br> -D AP_HAVE_RELIABLE_PIPED_LOGS<br> -D DYNAMIC_MODULE_LIMIT=256<br> -D HTTPD_ROOT="/etc/httpd"<br> -D SUEXEC_BIN="/usr/sbin/suexec"<br> -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"<br> -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"<br> -D DEFAULT_ERRORLOG="logs/error_log"<br> -D AP_TYPES_CONFIG_FILE="conf/mime.types"<br> -D SERVER_CONFIG_FILE="conf/httpd.conf"<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>21<br>22<br>23<br>24<br>25<br>26<br>27<br>关注到最后一行</p>
<p> -D SERVER_CONFIG_FILE="conf/httpd.conf"<br>1<br>所以,正在运行的服务器正在使用的配置文件为</p>
<p>/etc/httpd/conf/httpd.conf<br>1<br>编辑 Apache 配置文件<br>需要使用超级用户权限对配置文件进行更改,但是我们应先备份配置文件:</p>
<p>$ sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak<br>1<br>然后使用命令</p>
<p>$ sudo vim /etc/httpd/conf/httpd.conf<br>1<br>打开配置文件后,添加如下结点</p>
<p><VirtualHost *:80><br> ServerName subdomain.example.cn<br> DocumentRoot /home/website1<br></VirtualHost><br>1<br>2<br>3<br>4<br>其中,ServerName 字段为你要绑定的域名名称;DocumentRoot 为访问该绑定的域名时将访问的目录,以便从那里取出默认主页页面响应用户,该目录可以任意设置,但务必保证目录权限足够。保存退出,然后重启 httpd 服务:</p>
<p>$ sudo systemctl restart httpd.service<br>1<br>若没有任何输出到屏幕上,则为正常开启了服务,现在可以在客户端浏览器通过访问二级域名</p>
<p>subdomain.example.cn<br>1<br>来访问位于 /home/website1 目录下的这个网站。若还要添加站点,则再另行添加配置中的结点信息即可。<br>————————————————<br>版权声明:本文为CSDN博主「造轮使者」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。<br>原文链接:https://blog.csdn.net/jinhangdev/article/details/81254748</p><br><br>
来源:https://www.cnblogs.com/ydwzhang/p/11546639.html
頁:
[1]