linux运维笔记7

############################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/            ####刷新

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值