4.mysql数据库的基本管理
#### 1. Apachen的作用 ####
在web被访问的时通常使用http://的方式
http:// ##超文本传输协议
http:// 超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tenglne
#### 2.Apache的安装 ####
dnf install httpd.x86_64 -y
#### 3.Apache的启动 ####
systemctl enable --now httpd ##开启服务并设定服务为开机启动
firewall-cmd --list-all ##查看火墙信息
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效
#### 4.Apache的基本信息 ###
服务名称:httpd
配置文件:
/etc/httpd/conf/httpd.conf ##主配置文件
/etc/httpd/conf.d/*.conf ##子配置文件
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口: #http
443 #https
用户: apache
日志: /etc/httpd/logs
#### 5.Apache的基本配置 ####
#1.Apache端口修改#
vim /etc/httpd/conf/httpd.conf
[[email protected] westos]# mkdir -p /var/www/vhost/westos.org/{wty,zzw,rtt}
[[email protected] westos]# echo wty.westos.org> /var/www/vhost/westos.org/wty/index.html
[[email protected] westos]# echo zzw.westos.org> /var/www/vhost/westos.org/zzw/index.html
[[email protected] westos]# echo rtt.westos.org> /var/www/vhost/westos.org/rtt/index.html
[[email protected] westos]# vim /etc/httpd/conf.d/vhosts.conf
[[email protected] westos]# cat /etc/httpd/conf.d/vhosts.conf
<VirtualHost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName wty.westos.org
DocumentRoot /var/www/vhost/westos.org/wty
CustomLog logs/wty.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName zzw.westos.org
DocumentRoot /var/www/vhost/westos.org/zzw
CustomLog logs/zzw.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName rtt.westos.org
DocumentRoot /var/www/vhost/westos.org/rtt
CustomLog logs/rtt.log combined
</VirtualHost>
[[email protected] westos]# systemctl restart httpd
#在浏览器所在的主机上做域名解析#
[[email protected]_server ~]# vim /etc/hosts
172.25.254.118 www.westos.org wty.westos.org zzw.westos.org rtt.westos.org
[[email protected]_server ~]# ping zzw.westos.org
PING www.westos.org (172.25.254.118) 56(84) bytes of data.
64 bytes from www.westos.org (172.25.254.118): icmp_seq=1 ttl=64 time=0.234 ms
64 bytes from www.westos.org (172.25.254.118): icmp_seq=2 ttl=64 time=0.275
[[email protected] cgi]# dnf install mod_ssl -y
[[email protected] cgi]# mkdir /etc/httpd/tls
[[email protected] cgi]# openssl req --newkey rsa:2048 -nodes -sha256 -keyout /etc/httpd/tls/westos.org.key -x509 -days 365 -out /etc/httpd/tls/westos.org.crt
#########################Generating a RSA private key
..........................+++++
....................+++++
writing new private key to '/etc/httpd/tls/westos.org.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shaanxi
Locality Name (eg, city) [Default City]:Xi'an
Organization Name (eg, company) [Default Company Ltd]:WESTOS
Organizational Unit Name (eg, section) []:Linux
Common Name (eg, your name or your server's hostname) []:www.westos.org
Email Address []:[email protected]
#################################################################
[[email protected] cgi]# mkdir /var/www/vhost/westos.org/login
[[email protected] cgi]# vim /var/www/vhost/westos.org/login/index.html
[[email protected] westos.org]# cat /var/www/vhost/westos.org/login/index.html
login.westos.org
[[email protected] cgi]# vim /etc/httpd/conf.d/vhosts.conf
#[[email protected] westos.org]# cat /etc/httpd/conf.d/vhosts.conf
<VirtualHost *:80>
ServerName login.westos.org
RewriteEngine On
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1
</VirtualHost>
<VirtualHost *:443>
Servername login.westos.org
DocumentRoot /var/www/vhost/westos.org/login
CustomLog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/httpd/tls/westos.org.crt
SSLCertificateKeyFile /etc/httpd/tls/westos.org.key
</VirtualHost>
##################################################################
[[email protected] cgi]# systemctl restart httpd
#在在浏览器所在的主机上做域名解析#
[[email protected]_server ~]# vim /etc/hosts
[[email protected]_server ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
login.westos.org
#在网页中访问https://login.westos.org
##### 10.Squid+Apache #####
#Squid正向代理
实验环境
单网卡主机设定ip不能上网
双为网卡主机设定ip可以上网,设定ip2可以上网
实验效果
让网卡主机但浏览器可以访问互联网页
操作
#在双网卡主机中
dnf install squid -y
vim /etc/squid/squid.conf
59 http_access allow all
65 cache_dir ufs /var/spool/squid 100 16 256
systemctl start squid
nmcli connection show
nmcli connection delete ens3
vim /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3
ONBOOT=yes
NOOTPROTO=none
IPADDR=172.25.254.118
PREFIX=24
GATEWAY=172.25.254.250
DNS1=114.114.114.114
nmcli connection reload
#在单网卡主机中
vim /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3
ONBOOT=yes
NOOTPROTO=none
IPADDR=172.25.254.118
PREFIX=24
GATEWAY=172.25.254.250
在单网卡主机中选择
Network Proxy
172.25.254.118 3128
测试:
在单网卡主机中
ping www.baidu.com 不通
在浏览器中访问www.baidu.com可以
##Squid反相代理
实验环境
172.25.254.118 ##Apache服务器[深圳]
172.25.254.218 ##Squid,没有数据负责缓存[西安]
172.25.254.18 ##客户端
#在172.25.254.218中
vim /etc/squid/squid.conf
62 http_port 80 vhost vport ##vhost 支持虚拟域名 vport 支持虚拟端口
#当172.25.254.218的80端口被访问会从172.25.254.118的80端口缓存数据
63 cache_peer 172.25.254.118 parent 80 0 proxy-only
systemctl restart squid
[test]
firefox http:/172.25.254.218
访问看到的是172.25.254.118上的数据