运维学习之Apache的配置、访问控制、虚拟主机和加密访问https

apache

一、安装Apache服务

yum install httpd -y

systemctl start httpd

systemctl stop firewalld

systemctl enable httpd

systemctl disable firewalld

二、apache信息

1.apache的默认发布文件

index.html

在默认发布文件内写入要展示的内容,在浏览器中输入本机http://172.25.254.126可以看到内容

2.apache的配置文件

/etc/httpd/conf/httpd.conf

/etc/httpd/conf.d/*.conf

3.apache的默认发布目录

/var/www/html

4.apache的默认端口

80

三、apache的基本配置

1.修改默认发布文件

vim /etc/httpd/conf/httpd.conf

164     DirectoryIndex westos.html

systemctl restart httpd

2.修改默认发布目录

##当selinux是disable状态

vim /etc/httpd/conf/httpd.conf

120 DocumentRoot "/westos/www/test"

<Directory "/westos/www/test">

Require all granted

</Directory>

systemctl restart httpd

##当selinux是enforcing状态

vim /etc/httpd/conf/httpd.conf

120 DocumentRoot "/westos/www/test"

<Directory "/westos/www/test">

Require all granted

</Directory>

systemctl restart httpd

semanage fcontext -a -t httpd_sys_content_t ‘/westos(/.*)?‘

restorecon -RvvF /westos

修改/westos/html/westos文件内容

因为selinux为enforcing,需要修改新建目录的安全上下文,再刷新配置

重启服务后访问到westos目录

3.apache的访问控制

##设定ip的访问

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin"> ##允许所有人访问admin目录但是拒绝250主机

Order Allow,Deny

Allow from All

Deny from 172.25.254.250

</Directory>

order行按顺序执行,前者优先级大于后者

<Directory "/var/www/html/admin">       ##只允许250主机访问admin目录

Order Deny,Allow

Allow from 172.25.254.250

Deny from All

</Directory>

##设定用户的访问

htpasswd -m /etc/httpd/accessuser admin

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin">

AuthUserFile /etc/httpd/accessuser ##用户认证文件

AuthName "Please input your name and password !!" ##用户认证提示信息

AuthType basic ##认证类型

Require valid-user ##认证用户,认证文件中所有用户都可以通过

[Require user admin] ##只允许认证文件中admin用户访问,二写一

</Directory>

生成用户认证密匙

编辑配置文件如下

设定admin用户可以登陆

设定admin1用户不能登陆

admin1不能登陆

4.apache语言支持

php html cgi

html语言默认支持

php语言

vim index.php

<?php

phpinfo();

?>

yum install php -y

systemctl restart httpd

安装php

在默认发布目录下添加index.php文件,写入以下测试内容

测试成功!

cgi语言

mkdir /var/www/html/cgi

vim index.cgi

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print `date`;

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/cgi">

Options +ExecCGI

AddHandler cgi-script .cgi

</Directory>

systemctl restart httpd

cgi的发布文件编辑

给index.cgi加上可执行权限

修改default.conf文件

修改安全上下文

测试成功!

四、apache的虚拟主机

1.定义

可以让我们的一台apache服务器在被访问不同域名的时候显示不同的主页

2.建立测试页

mkdir  virtual/money.westos.com/html -p

mkdir  virtual/news.westos.com/html -p

echo "money.westos.com‘s page" >virtual/money.westos.com/html/index.html

echo "news.westos.com‘s page" >virtual/news.westos.com/html/index.html

创建news.westos.com和sports.westos.com目录,编辑两个发布文件如下

3.配置

vim /etc/httpd/conf.d/default.conf ##位指定域名的访问都访问default

<Virtualhost _default_:80> ##虚拟主机开启的端口

DocumentRoot "/var/www/html" ##虚拟主机的默认发布目录

CustomLog "logs/default.log" combined ##虚拟主机日志

</Virtualhost>

vim /etc/httpd/conf.d/news.conf ##指定域名news.westos.com的访问到指定默认发布目录中

<Virtualhost *:80>

ServerName "news.westos.com"

DocumentRoot "/var/www/virtual/news.westos.com/html"

CustomLog "logs/news.log" combined

</Virtualhost>

<Directory "/var/www/virtual/news.westos.com/html"> ##默认发布目录的访问授权

Require all granted

</Directory>

建立default.conf news.conf sports.conf三个文件作为访问文件

default.conf中的文件内容

news.conf中的文件内容

sports.conf中的文件内容

重启服务,在26主机中的/etc/hosts配置文件中写入本地解析如下

4.测试

在浏览器所在主机中

vim /etc/hosts

172.25.254.100 www.westos.com news.westos.com

测试结果如下

五、网页加密访问https

1.https定义

Hyper text transfer protocol over Secure socker layer

通过ssl

2.配置

yum install mod_ssl -y

yum install crypto-utils -y

genkey www.westos.com

/etc/pki/tls/private/www.westos.com.key

/etc/pki/tls/certs/www.westos.com.crt

genkey www.westos.com 生成证书

填写信息

选择不发送证书信息

不加密密钥

证书文件生成,检查http端口443,确定防火墙可以通过端口

测试,证书信息变为自己设定的内容

vim /etc/httpd/conf.d/login.conf

<Virtualhost *:443>

ServerName "login.westos.com"

DocumentRoot "/var/www/virtual/login.westos.com/html"

CustomLog "logs/login.log" combined

SSLEngine on ##开始https功能

SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt #证书

SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##密钥

</Virtualhost>

<Directory "/var/www/virtual/login.westos.com/html">

Require all granted

</Directory>

<Virtualhost *:80> ##网页重写实现自动访问https

ServerName login.westos.com

RewriteEngine on

RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

</Virtualhost>

##########################################################################

## ##

## ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301] ##

## ##

## ^(/.*)$ 客户主机在地址栏中写入的所有字符,不包含换行符 ##

## https:// 定向成为的访问协议 ##

## %{HTTP_HOST} 客户请求主机 ##

## $1 $1的值就表示^(/.*)$的值 ##

## [redirect=301] 临时重定向 302永久重定向 ##

## ##

##########################################################################

配置文件中添加生成的证书和密钥,配置各项和http加密访问有关的项

创建新的发布文件

mkdir  /var/www/virtual/login.westos.com/html -p

vim /var/www/virtual/login.westos.com/html/index.html

systemctl restart httpd

测试:

在客户主机中添加解析

vim /etc/hosts

172.25.254.100 login.westos.com

在真机本地解析中加入login.westos.com

访问http://login.westos.com 会自动跳转到

https://login.westos.com 实现网页数据加密传输

六、搭建简易论坛(安装包法)

安装所需的mariadb数据库,安装php插件,安装Apache,安装php-mysql服务

解压压缩包到/var/www/html下

修改readme文件中要求的文件权限为777,开启数据库服务

在浏览器中输入172.25.254.126/upload/install进入安装服务

检测全部通过

填写信息

论坛安装成功,可以用管理员身份进入论坛

时间: 2024-07-30 13:49:22

运维学习之Apache的配置、访问控制、虚拟主机和加密访问https的相关文章

运维学习笔记Apache服务

Apache HTTP SERVER Apache软件基金会的一个开放源代码的网页服务器软件 curl -I 查看网站的网页服务器类型 实验测试之前注意向发起访问请求的主机添加域名解析/etc/host 一.安装httpd yum install httpd systemctl start httpd systemctl enable httpd #开机启动 firewall-cmd  --permanent --add-service=http #将http服务添加至防火墙列表中 firewa

自动化运维工具Ansible-安装与配置(二)

1.Ansible的安装 一键式脚本安装,主要包含以下相关安装包python2.7setuptools模块pycrypto模块PyYAML模块MarkupSafe模块Jinja2模块paramiko模块simplejson模块ansible一键式安装脚本连接如下:链接:https://pan.baidu.com/s/15U5nRGcA_C0N5tRYJzRgLg 提取码:lxpg 2.配置 2.1.ansible配置文件解析(/etc/ansible/ansible.cfg) grep '^[a

运维学习之加密和解密

运维学习之加密与解密: 众所周知,在网络的世界里不存在绝对的安全性.各种钓鱼网站,病毒等等危害着我们的网 络环境.所以,作为一个运维人员,在我们利用网络进行通信时,保证通信的机密性.完整性.可用性是必要的. 我们的日常生活中有以下三点威胁网络安全的行为: 1.威胁机密性的攻击行为,它的途径是窃听.嗅探.扫描和通信量分析 2.威胁完整性的攻击行为,它的途径是更改.伪装.重放.否认 3.威胁可用性的攻击行为,它的途径是拒绝服务 为应对以上问题,我们在技术和服务两方面提出了解决方案: 从技术上我们使用

Linux运维学习之 —— 搭建本地yum源

yum是RPM的前端工具,通过yum命令可以帮我们自动解决安装rpm包之间的依赖关系.下面是搭建本地yum仓库的步骤: 1.挂载光盘(光盘为CentOS-6.5-x86_64-bin-DVD2.iso)     mount /dev/cdrom1 /media ls一下/media这个目录,可以看到以下内容 2.创建本地文件夹,将Packages下的rpm包全部拷贝到本地文件夹     mount /dev/cdrom1 /media/     cp -r /media/Packages/* /

linux 运维学习

Linux 运维学习笔记(一) 一. 配置网卡 1. 通过root账户登录后,输入setup命令. 2. 选择第三项"网络配置" 3. 继续选择"网卡设置" 4. 选择第一张网卡 5. 因为已经选择使用DHCP获取IP地址,所以IP地址不需要配,但是可以配一下DNS,然后保存退出! 6. 重启网卡(有三种方法) (1).ifup eth0 (2).etc/init.d/network restart (3)service network restart 7. 配置网

运维学习之网络管理&IP设置&网关、DNS、DHCP的设置

11.管理网络 1.ip基础知识 1.ipv4 2进制32位-----10进制 172.25.0.10/255.255.255.0 172.25.0.10:ip地址 255.255.255.0:子网掩码 子网掩码255位对应的ip位为网络位 子网掩码0对应的ip位为主机位 2.配置ip <<图形化>> 1.图形界面 nm-connection-editor 2.文本化图形 nmtui <<命令>> ifconfig 网卡 ip netmask ##临时设定

DayDayUP_Linux运维学习_oracle11g安装教程

1. 安装环境介绍 系统环境 虚拟机测试机 系统版本 linux redhat 6.5 x64 软件版本 linux.x64_oracle_11gR2 系统内存 2G 系统存储 40G 主机名 vmdbs ip地址 192.168.1.189 192.168.128.189 笔者当时安装操作系统时所选的安装包 1.1 Base System Base System 安装 8 个套件 Base System > Base Base System > Client management tools

linux运维之LAMP(apache+mariadb+php)搭建

linux运维之LAMP(apache+mariadb+php)搭建         LAMP 是Linux Apache MySQL(mariadb) PHP的简写,其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行php的脚本语言,其中mariadb为mysql的一个分支. 搭建环境: 系统: CentOS6.6-x86_64          httpd: httpd-2.4.9          mariadb: mariadb-5.5.43    

运维学习

运维学习第二弹: 一.centOS虚拟机的基本指令: 二.三大开源协定: 三.软件的一般四类文件: 二进制文件:可执行文件 windows=.exe(execute) /msi linux:ELF 头文件/库文件(用于应用程序和内核的链接): windows:dll(dynamic linked Library) linux:so(shared object): ko(lernel object): a 帮助文件:整个程序的使用说明书 配置文件:变量  就是这个文件自己的名字 任何文件的路径都由