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