Apache 服务应用配置
-
更改主配置文件参数
# 更改默认发布的 index.html 文件 DirectoryIndex westos.html index.html # 先访问westos.com,再访问index.com # 更改默认发布目录为/westos/web/http DocumentRoot "/westos/web/http" <Directory "/westos/web/http"> # 更改发布目录后需要授权该目录 Require all granted # 所有人可访问 </Directory> semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?' # 修改自建目录的安全上下文 restorecon -RvvF /westos/ # /westos文件及目录安全上下文重读 # 更改默认端口为8080 listen=8080 # 更改端口后,客户机访问需要指明端口号 # 访问时: 192.168.1.142:8080 firewalld-cmd --peranment --add-port=8080/tcp # 火墙添加端口后面加/tcp firewalld-cmd --reload # 火墙配置重读 semanage prot -a -t http_port_t -p tcp 6666 # selinux添加6666端口
虚拟主机配置
-
虚拟主机创建
为不同的web站点,配置同一台服务器rm -fr /etc/httpd/conf/httpd.conf yum reinstall httpd -y #建立目录和显示文件 mkdir -p /var/www/westos.com/news/html # 创建news站点发布目录 mkdir -p /var/www/westos.com/music/html # 创建music站点发布目录 echo hello,world > /var/www/html/index.html # 默认www站点发布内容hello,world echo <h1>news's page</h1> > /var/wwww/westos.com/news/html/index.html # news站点发布内容new's page echo <h1>musci's page</h1> > /var/wwww/westos.com/music/html/index.html # music站点发布内容music'page
#建立default虚拟部署位文件 cd /etc/httpd/conf.d vim a_default.conf 访问101默认访问的目录文件 <VirtualHost _default_:80> DocumentRoot /var/www/html # 发布目录 CustomLog logs/default.log combined # 日志地址 </VirtualHost> ## 指定 _default_:80 且没有写 servername 就是让有访问请求时,默认访问的是 /var/www/html 目录下的文件, ## 比如 news.westos.com | music.westos.com 指定了 servername,则访问这两个地址是,访问的是他们对应设置 ## 的发布目录,而 www.westos.com | test.westos.com 虽然解析了域名指向哪个IP,但服务器.conf文件没有专门指定 ## ServerName www.westos.com | ServerName test.westos.com,则当用户请求这两个域名时,该default.conf ## 文件生效,默认访问 /var/www/html 目录的文件
#建立news虚拟部署位文件 cd /etc/httpd/conf.d vim news.conf 访问101默认访问的目录文件 <VirtualHost *:80> ServerName news.westos.com DocumentRoot /var/www/westos.com/news/html CustomLog logs/default.log combined # 指 /etc/http/logs/news.log日志文件 </VirtualHost> <Directory "/var/www/westos.com/news/html"> # 目录授权 Require all granted # 所有人可访问 DirectoryIndex text.html index.html # 设置虚拟主机页面发布顺序,先发布text.html </Directory>
#建立music虚拟部署位文件 cd /etc/httpd/conf.d vim music.conf 访问101默认访问的目录文件 <VirtualHost *:80> ServerName music.westos.com DocumentRoot /var/www/westos.com/music/html CustomLog logs/default.log combined </VirtualHost> <Directory "/var/www/westos.com/music/html"> # 目录授权 Require all granted # 所有人可访问 </Directory>
## 注意:news.westos.com music.westos.com 要在本地hosts.conf文件中声明域名 systemctl restart httpd # 重启服务器
-
客户机测试