Linux网络服务_apache阿帕奇

4.Linux网络服务_apache阿帕奇

配置环境 更改IP与网关
vim /etc/sysconfig/network-scripts/ifcfg-eth0
这里写图片描述
更改主机名
hostnamectl set-hostname server3
更改yum源
vim /etc/yum.repos.d/rhel_dvd.repo
这里写图片描述
安装软件
yum install httpd httpd-manual -y
服务本身 帮助文档
启动
systemctl restart httpd
systemctl enable httpd
查看网络端口
ss -antlupe | grep httpd
这里写图片描述
火墙设定
firewall-cmd –list-all //列出火墙信息
这里写图片描述
firewall-cmd –permanent –add-service=http //永久允许http
firewall-cmd –reload //火墙重新加载
测试
http://172.25.254.100 //默认发布为官方网站说明性文字
这里写图片描述
http://172.25.254.100/manual //查看手册
默认发布目录
/var/www/html //默认发布目录 =====apache/
// 172.25.254.100/ ===172.25.254.100的/var/www/html
/var/www/html/index //apache的默认发布文件
vim /var/www/html/index //编辑默认内容
这里写图片描述
这里写图片描述

apache——–>提供协议http:// (超文本传输协议的一种)
curl -I www.baidu.com
curl -I baidu.com 查看网站服务类型
server 服务

基础信息

主配置文件 /etc/httpd/conf/httpd.conf
主配置目录 /etc/httpd/conf
子配置文件 /etc/httpd/conf.d/*.conf
子配置目录: /etc/httpd/conf.d/
默认发布目录 /var/www.html
默认发布文件 index.html
默认端口 80
默认安全上下文 httpd_sys_content_t
程序开启默认用户 apache
apache日志 /etc/httpd/logs/*

更改默认发布文件
vim /var/www/westos //原来的是index.html,这里创建新文件
hello westos

vim /etc/httpd/conf/httpd.conf //编辑配置文件第164行

DirectoryIndex westos //可指定多个
eg:DirectoryIndex westos index.html
rm -fr westos //原本是westos,删掉后变为index.html

这里写图片描述

systemctl restart httpd
pwd 查看当前目录

修改默认发布目录
mkdir /westos
vim /etc/httpd/conf/httpd.conf //编辑配置文件第120行
DocumentRoot “/westos/html”

systemctl restart httpd
!!SELinux为开启时需要修改安全上下文

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

查看错误

cd /etc/httpd/logs/
ls
vim error_log

vim /etc/httpd/conf/httpd.conf //编辑配置文件第120行
DocumentRoot “/westos/”

< Directory “/westos/” >
Require all granted
< /Directory >
这里写图片描述

systemctl restart httpd
若SELinux为开启,需要设定该目录的安全上下文
semanage fcontext -a -t httpd_sys_content_t ‘/westos(/.*)?’
rstorecon -RvvF /westos/
修该端口(默认端口80)
ss -antlupe | grep httpd //查看网络端口
这里写图片描述
vim /etc/httpd/conf/httpd.conf //编辑配置文件第42行
Listen 8080

systemctl restart httpd
ss -antlupe | grep httpd //查看网络端口
这里写图片描述
浏览器输入172.25.254.103:8080/index.html
- - - -报错—>需要修改防火墙支持端口
firewall-cmd –permanent –add-port=8080/tcp
firewall-cmd –reload
这里写图片描述

访问控制
8080还原80,默认发布目录还原回来,
针对与主机的访问控制(控制IP)
mkdir /var/www/html/test
touch /var/www/html/test/nihao
vim /etc/httpd/conf/httpd.conf
< Directory “/var/www/html/test” > //124行
!#Require all granted
Order Allow,Deny //读取顺序,先读Allow,后读Deny,后读的列表会覆盖先读取内容的部分
Allow from all
Deny from 172.25.254.20 //除了20都可以访问


Order Deny,Allow
Allow from 172.25.254.20
Deny from all //除了20都不能访问

systemctl restart 用户方式访问控制认证
cd /etc/httpd/
id admin //查看用户是否存在
[root@desktop3 httpd]# id admin
id: admin: no such user
htpasswd -cm webuser admin //c表示创建m表示用户
- - - - - - - -//第一次创建,第二次再创建就会覆盖,第二次以后不加c
[root@desktop3 httpd]# htpasswd -cm webuser admin
New password:
Re-type new password:
Adding password for user admin
cat webuser

[root@desktop3 httpd]# cat webuser
admin: apr1 a p r 1 2LIN90/t $ S8mJNiMNwWCdBQj4bPJOo0

htpasswd -cm webuser tom //创建用户放在webuser1文件下
cat webuser //验证会被覆盖

[root@desktop3 httpd]# cat webuser
tom: apr1 a p r 1 LVQtAgCJ $NzIrYfNSXg/FmNwAMe4Fm1

htpasswd -m webuser admin
cat webuser

[root@desktop3 httpd]# cat webuser
tom: apr1 a p r 1 LVQtAgCJ NzIrYfNSXg/FmNwAMe4Fm1admin: N z I r Y f N S X g / F m N w A M e 4 F m 1 a d m i n : apr1 ThTL4YUf T h T L 4 Y U f CxVreDz.xFGFGRU2d4JsC.

vim /etc/httpd/conf/httpd.conf //第123行

< Directory “/var/www/html/admin” >
#Require all granted
AuthUserfile /etc/httpd/webuser //路径
AuthName “Please input username and password”
//文字说明
AuthType basic //类型为basic
#Require user admin //只有admin可以进去,别的进不去
Require valid-user // //已创建的所有人都可以进入
< /Directory >

这里写图片描述

mkdir /var/www/html/admin
echo hello admin > /var/www/html/admin/index.html
systemctl restart httpd
ctrl+shift+delete删除浏览器缓存
这里写图片描述

设置虚拟主机地址(更改解析文件,能够打开子页面) 真机中
su - root //切换到超级用户
vim /etc/hosts //配置解析文件,在真机中设置即在真机中打开浏览器查看
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhovst6.localdomain6
172.25.254.250 content.example.com
172.25.254.103 www.westos.com news.westos.com money.westos.com login.westos.com music.westos.com
检测[root@foundation3 Desktop]# ping www.westos.com //能通则说明配置完成 虚拟机
[root@desktop3 httpd]# cd /etc/httpd/conf.d //打开配置文件目录
[root@desktop3 conf.d]# ls //查看配置文件
autoindex.conf README userdir.conf welcome.conf
[root@desktop3 conf.d]# vim a_default.conf //编辑默认解析文件
< VirtualHost default:80 >
DocumentRoot /var/www/html
Customlog logs/default.log combined
< /VirtualHost >

[root@desktop3 conf.d]# vim /etc/httpd/conf/httpd.conf
- - - - - //第31行查看默认路径 31 ServerRoot “/etc/httpd” 日志文件目录地址
[root@desktop3 www]# mkdir /var/www/html/virtual/news.westos.com/html -p //创建

子页
[root@desktop3 www]# mkdir /var/www/html/virtual/music.westos.com/html -p //创建
子页
[root@desktop3 html]# vim index.html //写入内容
[root@desktop3 html]# cat index.html
< h1 >nihao< /h1 >

[root@desktop3 html]# vim index.html
[root@desktop3 html]# cat index.html

< h1 >nihao_music< /h1 >

[root@desktop3 conf.d]# systemctl restart httpd //重启服务
[root@desktop3 conf.d]# vim news.conf //编辑子页面配置文件

< VirtualHost *:80 >
ServerName news.westos.com
DocumentRoot /var/www/virtual/news.westos.com/html
CustomLog logs/news.log combined //combined混合型日志
< /VirtualHost>
< Directory “/var/www/virtual/news.westos.com/html” >
Require all granted
< /Directory >

[root@desktop3 conf.d]# systemctl restart httpd
[root@desktop3 conf.d]# vim music.conf //编辑子页面配置文件

< VirtualHost *:80 >
ServerName music.westos.com
DocumentRoot /var/www/virtual/music.westos.com/html
CustomLog logs/music.log combined //combined混合型日志
< /VirtualHost >
< Directory “/var/www/virtual/music.westos.com/html”>
Require all granted
< /Directory>

combined混合型日志文件:登陆警告报错等所有类型的日志文件
这里写图片描述
这里写图片描述
这里写图片描述

日志文件地址
[root@desktop3 html]# cd /etc/httpd/
[root@desktop3 httpd]# ls
conf conf.d conf.modules.d logs modules run webuser
[root@desktop3 httpd]# cd /etc/httpd/logs/
[root@desktop3 logs]# ls
access_log default.log error_log music.log news.log nihao.html
阿帕奇支持的语言
html(静态) cgi(输入框)
不支持: php(动态)jsp
php的发布
root@desktop3 html]# yum install php -y //安装php
[root@desktop3 html]# systemctl restart httpd //重启服务
[root@desktop3 html]# vim index.php //编写php测试脚本
< ?php
phpinfo();
? >

[root@desktop3 html]# systemctl restart httpd
浏览器输入http://172.25.254.103/index.php //出现php界面安装成功
这里写图片描述

cgi的发布
[root@desktop3 html]# cd /var/www/html/
[root@desktop3 html]# ls
admin index index.html index.php test
[root@desktop3 html]# mkdir cgi
[root@desktop3 html]# ls
admin cgi index index.html index.php test
[root@desktop3 html]# cd cgi/
[root@desktop3 cgi]# ls
[root@desktop3 cgi]# vim index.cgi !/usr/bin/per1 print “Content-type: text/html\n\n”;
print “Hello,world.”;
print date;
[root@desktop3 cgi]# chmod +x index.cgi
[root@desktop3 cgi]# ls
Index.cgi
浏览器输入 http://172.25.254.103/cgi/index.cgi
- - - - - //此时缺少编译命令,阿帕奇自动将文本发送给浏览器
这里写图片描述
这里写图片描述
- - - - -//图形来自于说明文件172.25.254.103/manual
[root@desktop3 cgi]# ./index.cgi //执行
[root@desktop3 cgi]# ./index.cgi
Content-type: text/html

Hello, World.Tue Jan 30 03:06:39 EST 2018
[root@desktop3 cgi]# chmod +x index.cgi
[root@desktop3 cgi]# ls
index.cgi
[root@desktop3 cgi]# vim /etc/httpd/conf.d/
a_default.conf music.conf php.conf userdir.conf
autoindex.conf news.conf README welcome.conf
[root@desktop3 cgi]# vim /etc/httpd/conf.d/a_default.conf

< VirtualHost default:80 >
DocumentRoot /var/www/html
CustomLog logs/default.log combined
< /VirtualHost >
这里写图片描述
< Directory /var/www/html/cgi>
Options +ExecCGI
AddHandler cgi-script .cgi
< /Directory>

[root@desktop3 cgi]# systemctl restart httpd
输入172.25.254.101/cgi/index.cgi //查看能否打开
这里写图片描述

http —> 明文 https —> 密文 安装加密软件
[root@desktop3 cgi]# cd /etc/httpd/conf.d/
[root@desktop3 conf.d]# ls //查看是否存在配置文件
a_default.conf manual.conf news.conf README welcome.conf
autoindex.conf music.conf php.conf userdir.conf
[root@desktop3 conf.d]# yum install mod_ssl -y //安装加密软件
[root@desktop3 conf.d]# ls
a_default.conf manual.conf news.conf README userdir.conf
autoindex.conf music.conf php.conf ssl.conf welcome.conf
[root@desktop3 conf.d]# firewall-cmd –list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client http ssh
ports: 8080/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:

[root@desktop3 conf.d]# firewall-cmd –permanent –add-service=https
success
[root@desktop3 conf.d]# firewall-cmd –reload
success
[root@desktop3 conf.d]# systemctl restart httpd
输入https://172.25.254.103/验证
这里写图片描述
这里写图片描述

改为自己的key
[root@desktop3 conf.d]# yum install crypto-utils.x86_64 -y
[root@desktop3 conf.d]# genkey www.westos.com //打开,后为要设置的公司名称
│ The key will be stored
│ /etc/pki/tls/private/www.westos.com.key //私钥所在地址
│ The certificate stored in
│ /etc/pki/tls/certs/www.westos.com.crt //地址所在地址

这里写图片描述
这里写图片描述
这里写图片描述

此时,需要打开虚拟机,移动鼠标或者敲击键盘输入才会走动 一直动一直动,完成后: 这里写图片描述 这里写图片描述 这里写图片描述
[root@desktop3 conf.d]# ls
a_default.conf music.conf README userdir.conf
autoindex.conf news.conf ssl.conf welcome.conf
manual.conf php.conf tmprequest
[root@desktop3 conf.d]# vim ssl.conf
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
SSLCertificateChainFile /etc/pki/tls/certs/www.westos.com.crt
这里写图片描述
[root@desktop3 conf.d]# systemctl restart httpd
若用户信息与自己设置的不一致
在菜单中找出Customize找出自定义菜单
在Edit中找到Preference
在Advanced找到Certificates中的View Certificates
找到apache删除此证书文件,删除缓存,进入重新获取认证信息
查看认证信息
这里写图片描述

做一个加密的虚拟主机
443端口的虚拟机

[root@server3 html]# mkdir /var/www/virutal/login.westos.com/html -p//第归创建目录
[root@server3 html]# cd /var/www/virutal/login.westos.com/html
[root@server3 html]# vim /var/www/virutal/login.westos.com/html/index.html //创建默认文件

浏览器中做解析

[root@kiosk ~ ]$ vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.250 content.example.com
172.25.254.103 www.westos.com news.westos.com music.westos.com money.westos.com login.westos.com
[root@server3 html]# cd /var/www/html
[root@server3 html]# vim /etc/httpd/conf.d/ssl.conf //查看主配置文件中443端口设置

这里写图片描述

[root@server3 html]# vim login.html //建立默认文件

这里写图片描述
[root@server3 html]# cd /etc/httpd/conf.d/
[root@server3 conf.d]# ls
autoindex.conf php.conf ssl.conf welcome.conf
manual.conf README userdir.conf

>[root@server3 conf.d]# vim login.conf  //创建加密虚拟机配置文件
<VirtualHost *:443>
    ServerName login.westos.com     //网址
    DocumentRoot /var/www/virutal/login.westos.com/html //地址
    CustomLog logs/login.log combined       //日志文件地址,combined混合日志
    SSLEngine on        //ssl.conf第75行
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt    //ssl.conf第100行
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key   //ssl.conf第107行
</VirtualHost>
<Directory /var/www/virutal/login.westos.com/html>
    Require all granted
</Directory>

[root@server3 conf.d]# systemctl restart httpd
这里写图片描述

[root@server3 conf.d]# vim /etc/httpd/conf.d/login.conf //添加配置
< Virtualhost *:80 >
ServerName login.westos.com
RewriteEngine on //功能开启
RewriteRule ^(/.*) https:// h t t p s : / / 1 [redirect=301]
< /Virtualhost > //301临时保存,302永久保存
[root@server3 conf.d]# systemctl restart httpd

浏览器中输入login.westos.com 自动打开配置文件中的默认文件,前缀自动添加httpd://
这里写图片描述

这里写图片描述
!!!注意
^(/.*) //https:////访 / / 客 户 在 浏 览 器 地 址 栏 输 入 的 所 有 字 符 h t t p s : / / / / 强 制 客 户 加 密 访 问 1 //" 1(/.) 1 ” 表 示 ( / . ∗ ) 的值
[redirect=301] //301临时重写,在浏览器输入地址后先转码后浏览,每次都要
//302永久转换,只有第一次转码,后面都不需要
—-> manual中的提示

这里写图片描述

报错!

/var/log/messages //导入日志
systemctl restart httpd
cat /var/log/messages //查看日志

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值