Linux从入门到精通——Apache
###apache###
企业中常用的web服务,用来提供http:// (超文本传输协议)
httpd是apaceh服务器守护的进程
1.apache安装
yum install httpd -y ##apache软件的安装
yum install httpd—manual ##apache的手册
systemctl start httpd
systemctl enable httpd
systemctl start firewalld
firewall-cmd --list-all · ##列出火墙信息
firewall-cmd --permanent --add-server=http ##永久允许http
firewall-cmd --reload ##火墙的重新加载策略
netstat -antlupe|grep httpd ##查看监听端口,默认端口80
cd /var/www/html ##apache的 / 目录,默认发布目录
vim index.html ##默认发布文件 /var/www/html/index.html
<h1> hahahaha wangfang </h1>
测试:
在火狐浏览器上输入 172.25.254.110 ##会出现 hahahaha wangfang
ls
index.html
vim westos
<h1> wangfang westos's index.html </h1>
在火狐浏览器上输入172.25.254.110/westos ##会出现wangfang westos's index.html
yum install httpd—manual ##apache的手册
测试:
172.25.254.110/manual
2.apache的基础信息
主配置目录 /etc/httpd/conf
主配置文件 /etc/httpd/conf/httpd.conf
子配置目录 /etc/httpd/conf.d/
子配置文件 /etc/httpd/conf.d/*.conf
默认发布目录 /var/www/html
默认发布文件 index.html
默认端口 80
默认安全上下文 httpd_sys_content_t
程序开启默认用户 apache
apache日志 /etc/httpd/logs/*
(1)修改默认端口:
vim /etc/httpd/conf/httpd.conf
43 Listen 8080 ##修改默认端口为8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
netstat -antlupe|grep httpd ##查看监听端口,默认端口80
(2)修改默认发布文件:
vim /etc/httpd/conf/httpd.conf
DocumetRoot "/westos/html" ##目录
<Directory "/westos">
Require all granted
</Directory>
<IfModule dir_module> ##文件
DirectoryIndex westos index.html
</IfModule>
测试:
172.25.254.110 ##会出现westos里的内容
3.apache的访问控制
(1)
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">
Order Allow,Deny ##这里的命令,先读取allow,后读取deny
Allow from All ##先允许全部人访问
Deny from 172.25.254.110 ##再在允许访问的名单中将110这个ip覆盖掉
</Directory> ##除了110都可以访问
<Directory "/var/www/html/westos">
Order Deny,Allow ##这里的命令,先读取deny,后读取allow
Allow from 172.25.254.110 ##先禁止全部人访问
Deny from all ##再在禁止访问的名单中将110这个ip,设为允许访问
</Directory> ##除了110都不能访问
(2)设定用户登陆
cd /etc/httpd/conf/
htpasswd -cm westosuser wf ##建立用户(会要求设置密码)
htpasswd -m westosuser lsy
注意:当有一个用户存在的时候。就不能用 -cm 来建立新的用户,如果这样建立会将原来的用户覆盖掉。重新添加用户应该用 -m 。如果本身没有用户存在,则需要用 -cm
创建好用户后可以用 cat westosuser 这个命令查看
在设置好用户后,就可以设置用户输入账户和密码查看:(ps:要将上面的注释掉)
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">
# Order Allow,Deny
# Allow from All
# Deny from 172.25.254.110
AuthUserFile /etc/httpd/conf/westosuser
AuthTYpe basic
AuthName "please input your name and passwd !!"
#Require user wf ##只允许wf用户访问
Require valid-user ##允许所有有效用户访问,必须要写,不写的话,就没有密码验证的对话框
</Directory>
systemctl restart httpd
测试:
172.25.254.110/westos
4.apache的虚拟主机(为了访问不同的页面)
cd /var/www/
mkdir -p virtual/news/html
mkdir -p virtual/news/html
vim /var/www/virtual/news/html/index.html
<h1> news's page </h1>
vim /var/www/virtual/music/html/index.html
<h1> music's page </h1>
cd /etc/httpd/conf.d/
vim a_default.conf
<Virtualhost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/dedfault.log combined
</Virtualhost>
vim news.conf
<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot /var/www/virtual/news/html
CustomLog logs/news.log combined
</VirtualHost>
<Directory "/var/www/virtual/news/html">
Require all granted
</Directory>
vim music.conf
<VirtualHost *:80>
ServerName music.westos.com
DocumentRoot /var/www/virtual/music/html
CustomLog logs/music.log combined
</VirtualHost>
<Directory "/var/www/virtual/music/html">
Require all granted
</Directory>
systemctl restart httpd
测试:
vim /etc/hosts ##做域名解析
172.25.254.110 www.westos.com news.westos.com music.westos.com
5.php 和 cgi
cd /var/www/html/
vim index.php
<?php
phpinfo();
?>
yum install php -y
测试:
172.25.254.110/index.php
cd /var/www/html/
mkdir cgi
cd cgi/
vim index.cgi
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "Hello,wf.";
chmod 755 index.cgi
./index.cgi
vim a_dedault.conf
<Virtualhost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/dedfault.log combined
</Virtualhost>
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
测试:
172.25.254.110/cgi/index.cgi
6.apache的签证
yum install mod_ssl -y
cd /etc/httpd/conf
vim ssl.conf
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ##证书
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##密钥
systemctl restart httpd
yum install crypto-utiles -y
genkey www.westos.com ##获得证书
systemctl restart httpd
6.网页重写(加密访问) 将 hppt:// 变成 hppts://
cd /etc/httpd/conf.d
cp news.conf login.conf
vim login.conf
<VirtualHost *:80>
ServerName login.westos.com
DocumentRoot /var/www/virtual/login/html
CustomLog logs/login.log combined
</VirtualHost>
<Directory "/var/www/virtual/login/html">
Require all granted
</Directory>
vim /var/www/virtual/login/html/index.html
<h1> login's page </h1>
测试:
需要手动加 https://
vim news.conf
<VirtualHost *:443>
ServerName login.westos.com
DocumentRoot /var/www/virtual/login/html
CustomLog logs/login.log combined
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
SSLEngine on
</VirtualHost>
<Directory "/var/www/virtual/login/html">
Require all granted
</Directory>
<VirtualHost *:80>
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
测试:
不需要手动加 login.westos.com
注意:
^(/.*)$ ##客户在浏览器地址栏中输入的所有字符
https:// ##强制客户加密访问
%{HTTP_HOST} ##客户请求主机
$1 ##表示 ^(/.*)$ 的值
[redirect=301] ##临时重写 302永久转换
7.squid(FQ)
在没有权限查看某网站,另一个主机可以访问的时候,可以在可以访问的主机上装squid,然后开启服务,开通端口,在访问不了的主机上,输入可查看主机的ip和端口,就可以查看某网站
yum install squid -y
systemctl start squid
vim /etc/squid/squid.conf
http_access allow all
http_port 3128
cache_dir ufs /var/spool/squid 100 16 256
测试:
在真机上,preferences -> Advanced -> network -> setting -> Manual proxy configuration -> 172.25.254.110 3128
8.辅助squid
yum install squid -y
systemctl start squid
vim /etc/squid/squid.conf
http_access allow all
http_port 80 vhost vport
cache_peer 172.25.254.110 parent 80 0 proxy-only round-robin originserver name=web1 weight=3
cache_peer 172.25.254.111 parent 80 0 proxy-only round-robin originserver name=web2
cache_peer_domain web1 web2 www.westos.com
cache_dir ufs /var/spool/squid 100 16 256
转载于:https://www.cnblogs.com/wf-aiyouwei/p/9482900.html
Linux从入门到精通——Apache相关推荐
- Kali Linux 从入门到精通(八)-主动信息收集
Kali Linux 从入门到精通(八)-主动信息收集 基本介绍 直接与目标系统交互通信 无法避免留下访问的痕迹 使用受控的第三方电脑进行探测 使用代理或已经被控制的主机 做好被封杀的准本 使用噪声迷 ...
- linux学生入门,Linux入门之《Linux从入门到精通》
Linux是目前增长最迅速的操作系统.<Linux从入门到精通>由浅入深.循序渐进地向读者介绍Linux的基本使用和系统管理.全书内容包括 Linux概述.Linux安装.Linux基本配 ...
- ubuntu php入门教程,《Ubuntu Linux从入门到精通》PDF 下载_IT教程网
资源名称:<Ubuntu Linux从入门到精通>PDF 下载 内容简介: <Ubuntu Linux从入门到精通>详细介绍Ubuntu Linux操作系统,<Ubunt ...
- Linux从入门到精通系列之PPTP
Linux从入门到精通系列之PPTP 今天我们来说下怎么在linux环境下如何搭建PPTP-×××,PPTP(Point to Point Tunneling Protocol),即点对点隧道协议.该 ...
- Kali Linux 从入门到精通(十一)–提权
Kali Linux 从入门到精通(十一)–提权 本地提权 已实现本地低权限账号登录 远程溢出 直接获得账号密码 希望获取更高权限 实现对目标进一步控制 系统之间权限隔离 操作系统安全的基础 用户空间 ...
- Kali Linux 从入门到精通(十)-漏洞挖掘之缓冲区溢出
Kali Linux 从入门到精通(十)-漏洞挖掘之缓冲区溢出 程序漏洞从哪里来? 罪恶的根源:变量 数据与代码边界不清(注入攻击) 最简漏洞原理-shell 脚本漏洞(本质:输入数据本身,程序本身没 ...
- Kali Linux 从入门到精通(五)-测试环境准备
Kali Linux 从入门到精通(五)-测试环境准备 准备实验环境 渗透非系统授权的弊端 搭建自己的实验环境 安装虚拟机 微软最新软件 http://msdn.microst.com/en-ca/s ...
- Kali Linux 从入门到精通(三)-入侵系统定制
Kali Linux 从入门到精通(三)-入侵系统定制 定制 网络配置 临时IP地址 dhclient eth0 ifconfig eth0 192.168.11/24 route add defau ...
- Kali Linux 从入门到精通(二)-安装
Kali Linux 从入门到精通(二)-安装 Kail Linux 安装 持久加密USB安装-1 LUSK:Linux Unified Key Setup 磁盘分区加密规范 不依赖与操作系统的磁盘级 ...
最新文章
- Caffe源码中layer文件分析
- 转载:python原生态的输入窗口抖动+输入特效
- 医 系统 springboot搜索到的spring boot 的javaweb项目
- nginx启动只有master没有worker_深入浅出Nginx
- linux内核更新/修补程序,Ubuntu 18.04.3 LTS无需重启即可轻松修补Linux内核
- oledb32.dll的作用
- TensorFlow实战-AlexNet
- Solr 4.3.0 配置Data import handler时出错
- 使用MegaCli工具,在线调整raid配置
- mysql 5.5 编译安装教程,Centos6下mysql 5.5.* 编译安装步骤详解
- linux找回删除的文件6,在Centos6/RHEL6上恢复ext4文件系统下误删除的文件
- Ciesz się Polską
- 湖南2021年高考成绩查询与录取查询课件,@所有高考生,高考成绩和录取动态查询方式公布...
- java中的并发是什么意思_java中的并发是什么
- hbuild html5打包apk,使用HBuilder打包5+App
- 码农与程序员两种不同称呼,有什么本质上的区别?
- 查询电脑ip地址方法
- PostgreSQL 生成随机数字、字符串、日期、验证码以及 UUID
- linux用户行为日志审计方案(sudo)
- SpringCloud与微服务Ⅷ --- Hystrix断路器