############################Apache服务器的相关配置#########################
----------------------------------------------------------------------
hostnamectl set-hostname apache.example.com ####修改主机名
firewall-cmd --list-all ####查询当前防火墙策略
firewall-cmd --permanent --add-service=http ####配置防火墙打开http协议,并保存,以致重启有效
firewall-cmd --permanent --add-service=https
firewall-cmd --reload ####防火墙策略配置后重新载入
firewall-cmd --list-all ####查询当前防火墙策略
----------------------------------------------------------------------
cd /var/www/html
vim index.html ####默认访问文件
------------------------------------------------------------------
########################修改默认访问目录,修改安全上下文###############
mkdir /www/html -p ####创建访问目录
vim westos ####编写文件
vim /etc/httpd/conf/httpd.conf ####编辑主配置文件
----------------------------------
<IfModule dir_module>
DirectoryIndex westos index.html
</IfModule>
----------------------------------
DocumentRoot "/www/html"
<Directory "/www">
Require all granted
</Directory>
----------------------------------
ls -Z /var/www/ ####查看安全上下文
semanage fcontext -a -t httpd_sys_content_t 'www(/.*)?' ####修改安全上下文
restorecon -RvvF /www/ ####刷新
##############################创建配置虚拟主机############################
------------------------------------------------------------------
cd /etc/httpd/conf.d/
mkdir /var/www/news
mkdir /var/www/music
echo news.westos.com > /var/www/news/westos
echo music.westos.com > /var/www/music/westos
vim default.conf
----------------------------------------------
<Virtualhost _default_:80>
Documentroot /var/www/html
customlog "logs/default.log" combine
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
---------------------------------------------
vim news.conf
---------------------------------------------
<Virtualhost *:80>
Servername news.westos.com
Documentroot /var/www/news
customlog "logs/news.log" combine
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
---------------------------------------------
vim music.conf
---------------------------------------------
<Virtualhost *:80>
Servername music.westos.com
Documentroot /var/www/music
customlog "logs/music.log" combine
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
---------------------------------------------
systemctl restart httpd
####编辑真机hosts文件#######
vim /etc/hosts
---------------------------------------------
172.25.254.32 www.westos.com news.westos.com music.westos.com
---------------------------------------------
#######################配置基于用户的身份验证###################
htpasswd -m apacheusr admin ####创建用户密码
----------------------------------------------------------------
<Virtualhost *:80>
Servername news.westos.com
Documentroot /var/www/news
customlog "logs/news.log" combined
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
<Directory /var/www/news/admin>
Authuserfile /etc/httpd/conf/apacheusr
Authname "Please input your name and passwd"
Authtype basic
Require valid-user
#########################自定义自签名证书######################
yum install mod_ssl -y ####安装软件
mkdir /var/www/login
vim login.conf
----------------------------------------------------------------
<Virtualhost *:443>
Servername login.westos.com
Documentroot /var/www/login
Customlog "logs/login.log" combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/apache.example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/apache.example.com.key
</Virtualhost>
<Directory "var/www/login">
Require all granted
</Directory>
<Virtualhost *:80>
Servername login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
--------------------------------------------------------------------
yum install crypto-utils -y
genkey apache.example.com
systemctl restart httpd
----------------------------------------------------------------------
hostnamectl set-hostname apache.example.com ####修改主机名
firewall-cmd --list-all ####查询当前防火墙策略
firewall-cmd --permanent --add-service=http ####配置防火墙打开http协议,并保存,以致重启有效
firewall-cmd --permanent --add-service=https
firewall-cmd --reload ####防火墙策略配置后重新载入
firewall-cmd --list-all ####查询当前防火墙策略
----------------------------------------------------------------------
cd /var/www/html
vim index.html ####默认访问文件
------------------------------------------------------------------
########################修改默认访问目录,修改安全上下文###############
mkdir /www/html -p ####创建访问目录
vim westos ####编写文件
vim /etc/httpd/conf/httpd.conf ####编辑主配置文件
----------------------------------
<IfModule dir_module>
DirectoryIndex westos index.html
</IfModule>
----------------------------------
DocumentRoot "/www/html"
<Directory "/www">
Require all granted
</Directory>
----------------------------------
ls -Z /var/www/ ####查看安全上下文
semanage fcontext -a -t httpd_sys_content_t 'www(/.*)?' ####修改安全上下文
restorecon -RvvF /www/ ####刷新
systemctl restart httpd ####重启httpd服务
##############################创建配置虚拟主机############################
------------------------------------------------------------------
cd /etc/httpd/conf.d/
mkdir /var/www/news
mkdir /var/www/music
echo news.westos.com > /var/www/news/westos
echo music.westos.com > /var/www/music/westos
vim default.conf
----------------------------------------------
<Virtualhost _default_:80>
Documentroot /var/www/html
customlog "logs/default.log" combine
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
---------------------------------------------
vim news.conf
---------------------------------------------
<Virtualhost *:80>
Servername news.westos.com
Documentroot /var/www/news
customlog "logs/news.log" combine
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
---------------------------------------------
vim music.conf
---------------------------------------------
<Virtualhost *:80>
Servername music.westos.com
Documentroot /var/www/music
customlog "logs/music.log" combine
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
---------------------------------------------
systemctl restart httpd
####编辑真机hosts文件#######
vim /etc/hosts
---------------------------------------------
172.25.254.32 www.westos.com news.westos.com music.westos.com
---------------------------------------------
#######################配置基于用户的身份验证###################
htpasswd -m apacheusr admin ####创建用户密码
----------------------------------------------------------------
<Virtualhost *:80>
Servername news.westos.com
Documentroot /var/www/news
customlog "logs/news.log" combined
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
<Directory /var/www/news/admin>
Authuserfile /etc/httpd/conf/apacheusr
Authname "Please input your name and passwd"
Authtype basic
Require valid-user
</Directory>
#########################自定义自签名证书######################
yum install mod_ssl -y ####安装软件
mkdir /var/www/login
vim login.conf
----------------------------------------------------------------
<Virtualhost *:443>
Servername login.westos.com
Documentroot /var/www/login
Customlog "logs/login.log" combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/apache.example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/apache.example.com.key
</Virtualhost>
<Directory "var/www/login">
Require all granted
</Directory>
<Virtualhost *:80>
Servername login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
--------------------------------------------------------------------
yum install crypto-utils -y
genkey apache.example.com
systemctl restart httpd