apache(Web服务器):
Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。同时Apache音译为阿帕奇,是北美印第安人的一个部落,叫阿帕奇族,在美国的西南部。也是一个基金会的名称、一种武装直升机等等。
一·安装阿帕奇部署
设置ip、配置yum源、安装阿帕奇
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# netstat -antlupe | grep httpd
tcp6 0 0 :::80 :::* LISTEN 0 27316 1679/httpd
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.html
[root@localhost html]# cat index.html
hello
浏览器:172.25.254.119
[root@localhost html]# vim test.html
[root@localhost html]# cat test.html
test
浏览器:172.25.254.119/test.html
浏览器:172.25.254.119
浏览器:172.25.254.119/test.html
二·更改端口
[root@localhost html]# vim /etc/httpd/conf/httpd.conf ##更改端口为8080
42 Listen 8080
[root@localhost html]# systemctl restart httpd ##重启
[root@localhost html]# netstat -antlupe | grep httpd ##查看端口
浏览器:172.25.254.119 ##会报错(需要修改防火墙支持端口)
[root@localhost html]# vim /etc/httpd/conf/httpd.conf ##改回原来端口80
Listen 80
[root@localhost html]# systemctl restart httpd
浏览器:172.25.254.119/test.html
当端口为8080时:
当端口改回原来80时:
三·
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# mkdir /westos/html -p
[root@localhost html]# cd /westos/html/
[root@localhost html]# vim index.html ##默认发布文件
[root@localhost html]# cat index.html
123
[root@localhost html]# vim /etc/httpd/conf/httpd.conf ##在主配置文件中编写内容
注释119 DocumentRoot "/www/html"
120 DocumentRoot "/westos/html" ##添加120~123内容
121 <Directory "/westos">
122 require all granted
123 </Directory>
[root@localhost html]# systemctl restart httpd
[root@localhost html]# vim test.html
[root@localhost html]# cat index.html
456
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
123 DirectoryIndex test.html ##添加
[root@localhost html]# systemctl restart httpd
浏览器:172.25.254.119/test.html
[root@localhost html]# ls
index.html test.html
[root@localhost html]# mkdir linux ##建立默认发布目录
[root@localhost html]# cd linux
[root@localhost linux]# ls
[root@localhost linux]# vim index.html
[root@localhost html]# cat index.html
789
[root@localhost linux]# vim test.html
[root@localhost html]# cat test.html
098
[root@localhost linux]# vim /etc/httpd/conf/httpd.conf
121 <Directory "/westos/html/linux"> ##修改
125 <Directory "/westos">
126 require all granted ##添加125~128内容
127 DirectoryIndex test.html
128 </Directory>
[root@localhost linux]# systemctl restart httpd
浏览器:172.25.254.119/linux
浏览器:172.25.254.119/test.html
浏览器:172.25.254.119/linux
四·访问认证
1、基于ip
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir westos
[root@localhost html]# ls
index.html test.html westos
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
打开119 DocumentRoot "/var/www/html"
注释120 DocumentRoot "/westos/html"
121 <Directory "/var/www/html/westos">
122 Order Allow,Deny ##先读Allow后读Deny
123 Allow from All ##都可以
124 Deny from 172.25.254.71 ##不可以
125 </Directory>
##除了 172.25.254.71 登陆不成功,其余的都可以
[root@localhost html]# systemctl restart httpd
浏览器分别输入:172.25.254.119 ##登陆成功
172.25.254.71 ##登录失败
修改主配置文件/etc/httpd/conf/httpd.conf
浏览器:172.25.254.119
浏览器:172.25.254.71
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
121 <Directory "/var/www/html/westos">
122 Order Deny,Allow ##先读deny,后读allow
123 Allow from 172.25.254.119 ##唯一一个可以
124 Deny from All ##不可以
125 </Directory>
[root@localhost html]# systemctl restart httpd
浏览器:172.25.254.119
172.25.254.71
浏览器:172.25.254.119
浏览器:172.25.254.71
2、基于用户
[root@localhost ~]# htpasswd -cm apacheuser tom ##建立新的用户
[root@localhost ~]# cat apacheuser ##查看
tom:$apr1$5Iyu3qNP$fJIPyW0FjcNT4w.8DoaHE0
[root@localhost ~]# htpasswd -m apacheuser admin ##第二次不用-c,否则会被覆盖
[root@localhost ~]# cat apacheuser
tom:$apr1$5Iyu3qNP$fJIPyW0FjcNT4w.8DoaHE0
admin:$apr1$1gm/pVqK$czap7dZhX/7XQWF2iAr4v/
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
注释120~125
126 <Directory "/var/www/html/westos">
127 AuthUserFile /etc/httpd/apacheuser
128 AuthName "Piease input user and password !!"
129 Require user admin ##设定admin用户
130 </Directory>
[root@localhost ~]# systemctl restart httpd
浏览器:172.25.254.119/westos/
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
126 <Directory "/var/www/html/westos">
127 AuthUserFile /etc/httpd/apacheuser
128 AuthName "Piease input user and password !!"
129 Require valid-user ##设定新建用户
130 </Directory>
[root@localhost ~]# systemctl restart httpd
浏览器:172.25.254.119/westos/
设定admin用户
浏览器172.25.254.119/westos/ 需要密码
登陆成功,可以查看:
设定新建用户
浏览器172.25.254.119/westos/
五·阿帕奇的虚拟主机设置
在真机中:
[root@foundation71 Desktop]# vim /etc/hosts ##解析文件
172.25.254.119 www.westos.com news.westos.com music.westos.com ##添加解析
在desktop中:
[root@localhost ~ cd /var/httpd/conf.d/
[root@localhost conf.d]# ls
autoindex.conf README welcome.conf
manual.conf userdir.conf
[root@localhost conf.d]# vim default.conf ##编写设定配置文件
<Virtualhost _default_:80>
DocumentRoot /var/www/html ##编写内容
CustomLog "logs/default.log" combined
</VirtualHost>
[root@localhost conf.d]# mkdir /var/www/virtual/westos.com/news -p ##建立目录
[root@localhost conf.d]# mkdir /var/www/virtual/westos.com/music -p ##建立目录
[root@localhost conf.d]# vim /var/www/virtual/westos.com/news/index.html
<h1>news'spage</h1> ##编写
[root@localhost conf.d]# vim /var/www/virtual/westos.com/music/index.html
<h1>music's page</h1> ##编写
[root@localhost conf.d]# vim news.conf ##配置文件
<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot "/var/www/virtual/westos.com/news ##编写内容
</VirtualHost>
<Directory "/var/www/virtual/westos.com/news/">
Require all granted
</Directory>
[root@localhost conf.d]# vim music.conf
<VirtualHost *:80>
ServerName music.westos.com
DocumentRoot "/var/www/virtual/westos.com/music/" ##编写内容
CustomLog "logs/music.log " combined
</VirtualHost>
<Directory "/var/www/virtual/westos.com/music/">
Require all granted
</Directory>
[root@localhost conf.d]# systemctl restart httpd
浏览器:www.westos.com
news.westos.com
music.westos.com
在设定配置文件 default.conf 中:
在配置文件news.conf 中:
在配置文件music.conf 中:
浏览器:www.westos.com
news.westos.com
music.westos.com
简述HTTPS和HTTP区别:
HTTPS是以安全为目标的HTTP通道,简单讲是HTTP的安全版。https协议需要到ca申请证书,一般免费证书很少,需要交费。而http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议http和https使用的是完全不同的连接方式用的端口也不一样,前者是80,后者是443。http的连接很简单,是无状态的。HTTPS协议是由SSL+HTTP协议构建的可进行加密传输、身份认证的网络协议 要比http协议安全。
六·PHP查件管理
[root@localhost conf.d]# yum install mod_ssl -y
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# yum install crypto-utils -y
[root@localhost conf.d]# genkey www.westos.com
Next、1024、第一次下载、第二次下载需要在虚拟机中敲、No、Next、输入CH,shannxi,xi'an,westos,linux,Next、
[root@localhost conf.d]# vim /etc/httpd/conf.d/ssl.conf
100 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ##修改内容
107 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
[root@localhost conf.d]# systemctl restart httpd
浏览器:https://www.westos.com
genkey www.westos.com
操作完以上步骤后会出现私钥文件
在配置文件中 /etc/httpd/conf.d/ssl.conf 修改
浏览器https://www.westos.com 证书认证
选择I Under….. Add …..
点击Get…. Confirm…..
展示证书:
在真机中加入解析文件
[root@foundation71 Desktop]# vim /etc/hosts
172.25.254.119 login.westos.com
在desktop中:
[root@localhost conf.d]# vim login.conf ##编写配置文件
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# mkdir -p /var/www/virtual/westos.com/login/ ##建立目录
[root@localhost conf.d]# vim /var/www/virtual/westos.com/login/index.html
[root@localhost conf.d]# cat /var/www/virtual/westos.com/login/index.html
<h1>login's page</h1>
[root@localhost conf.d]# systemctl restart httpd
浏览器:login.westos.com
在配置文件login.conf 中编写
浏览器login.westos.com ,证书认证后可以查看
当输入login.westos.com会自动跳转到https加密方式。
七·CGI语言支持
[root@localhost conf.d]# yum install php -y
[root@localhost conf.d]# cd /var/www/html
[root@localhost html]# ls
index.html test.html westos
[root@localhost html]# vim index.php ##编写配置文件
[root@localhost html]# cat index.php
<?php
phpinfo();
?>
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
179 DirectoryIndex index.php index.html ##修改
[root@localhost html]# systemctl restart httpd
浏览器:172.25.254.119
在主配置文件 /etc/httpd/conf/httpd.conf 中修改
浏览器:172.25.254.119
[root@localhost html]# ls
index.html index.php test.html westos
[root@localhost html]# mkdir cgi ##建立目录
[root@localhost html]# ls
cgi index.html index.php test.html westos
[root@localhost html]# vim cgi/index.cgi
[root@localhost html]# cat cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
[root@localhost html]# chmod +x cgi/index.cgi ##赋予权限
[root@localhost html]# ./cgi/index.cgi ##查看
Content-type: text/html
Wed 30 May 23:24:57 EDT 2018
浏览器:172.25.254.119/cgi/index.cgi ##看不到时间,看见的是编写的内容
[root@localhost html]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# ls
[root@localhost conf.d]# vim default.conf ##编写配置文件
<Directory "/var/www/html/cgi">
Options +ExecCGI ##添加编写内容
AddHandler cgi-script .cgi
DirectoryIndex index.cgi
</Directory>
[root@localhost conf.d]# systemctl restart httpd
浏览器:172.25.254.119/cgi/index.cgi ##可以查看到时间
浏览器:172.25.254.119/cgi/index.cgi 只看到内容,不执行
在配置文件 default.conf 中添加内容:
再次172.25.254.119/cgi/index.cgi 执行成功
九·创建论坛
下载Discuz_X3.2_SC_UTF8.zip
[root@localhost ~]# yum install php-mysql -y
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
cgi Discuz_X3.2_SC_UTF8.zip index.html index.php test.html westos
[root@localhost html]# unzip Discuz_X3.2_SC_UTF8.zip ##解压
[root@localhost html]# ls
cgi index.html readme upload westos
Discuz_X3.2_SC_UTF8.zip index.php test.html utility
[root@localhost html]# chmod 777 /var/www/html/upload/ -R ##赋予权限
[root@localhost html]# systemctl restart httpd
浏览器:172.25.254.119/upload/install/
浏览器:172.25.254.119/upload/install/ 点击我同意、下一步、全新安装、
输入数据库密码,以及管理员密码
数据库密码若不记得,可以用安全初始化脚本再次设置
mysql_secure_installation
安装成功后在有上角登陆
登陆成功后界面:
Squid cache:
(简称为Squid)是一个流行的自由软件(GNU通用公共许可证)的代理服务器和Web缓存服务器。Squid有广泛的用途,从作为网页服务器的前置cache服务器缓存相关请求来提高Web服务器的速度,到为一组人共享网络资源而缓存万维网,域名系统和其他网络搜索,到通过过滤流量帮助网络安全,到局域网通过代理上网。Squid主要设计用于在Linux一类系统运行。
Squid是一种在Linux系统下使用的优秀的代理服务器软件。squid不仅可用在Linux系统上,还可以用在AIX、Digital Unix、FreeBSD、HP-UX、Irix、NetBSD、Nextstep、SCO和Solaris等系统上。Squid与Linux下其它的代理软件如Apache、Socks、TIS FWTK和delegate相比,下载安装简单,配置简单灵活,支持缓存和多种协议。
十·squid代理
1、正向代理
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 ##修改
IPADDR=172.25.254.119
NETMASK=255.255.255.0
GATEWAY=172.25.254.250
DNS1=114.114.114.114
[root@localhost ~]# systemctl restart network ##重启网络
[root@localhost ~]# yum install squid -y ##安装
[root@localhost ~]# vim /etc/squid/squid.conf
http_access allow all ##修改
cache_dir ufs /var/spool/squid 100 16 256 ##打开
[root@localhost ~]# systemctl restart squid
[root@localhost ~]# systemctl start squid
浏览器:www.baidu.com
修改/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/squid/squid.conf 修改56行,打开62行
浏览器:www.baidu.com
设置代理:
1、点击Advanced Network Settings..
2、点击Manual… 输入服务端ip 端口为3128 选择Use this…. OK
2、反向代理
(server)
[root@linux ~]# yum install squid -y
[root@linux ~]# vim /etc/squid/squid.conf
56 http_access allow all ##修改
59 http_port 80 vhost vport ##修改
60 cache_peer 172.25.254.119 parent 80 0 proxy-only ##添加
63 cache_dir ufs /var/spool/squid 100 16 256 ##打开
[root@linux ~]# systemctl restart squid
[root@linux ~]# systemctl stop firewalld
[root@linux ~]# yum install httpd -y
(desktop)
[root@localhost ~]# cd /var/www/html
[root@localhost html]# ls
cgi index.html readme upload westos
Discuz_X3.2_SC_UTF8.zip index.php test.html utility
[root@localhost html]# vim index.html
172.25.254.119
[root@localhost html]# systemctl restart httpd
浏览器:172.25.254.219
关闭代理:
浏览器:172.25.254.219