########################################
#关闭selinux
getenfoce #查看selinux的状态
#1.apache
#企业中常用的web服务,用来提供http://(超文本传输协议)
2.apache的安装部署
yum install httpd -y #apache软件
yum install -y httpd-manual #apache的手册
systemctl enable httpd
firewall-cmd --permanent --add-service=http #火墙允许http
firewall-cmd --reload
firewall-cmd --list-all
/var/www/html #apache的根目录,默认发布目录
/var/www/html/index.html #apache的默认发布文件
vim /var/www/html/index.html
<h1>hello westos</h1>
#测试
http://172.25.3.103
http://172.25.3.103/manual
3.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/*
修改默认端口:
vim /etc/httpd/conf/httpd.conf
43 Listen 8080 ###修改默认端口为8080
firewall-cmd --permanent --add-port=8080/tcp #防火墙允许8080端口
firewall-cmd --reload
修改默认发布文件
默认发布文件就是访问apache时没有指定文件名时默认访问的文件
这个文件可以指多个,有访问顺序
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex westos index.html #当westos不存在时访问index.html
修改默认发布目录
120 DocumentRoot "/westos/html"
121 <Directory "/westos">
Require all granted
</Directory>
###################################################
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
{
<h1>test page</h1>
}
vim /etc/httpd/conf/httpd.conf
{
<Directory "/var/www/html/westos">
Order Allow,Deny # 先读Allow 后读 Deny
Allow from All
Deny from 172.25.3.250 #读到Deny会覆盖Allow
</Directory>
}
systemctl restart httpd
指定用户访问
htpasswd -cm westosuser admin
cat westosuser
htpasswd -m westosuser admin1
vim /etc/httpd/conf/httpd.conf
{
<Directory "/var/www/html/westos">
AuthUserFile /etc/httpd/conf/westosuser
AuthType basic
AuthName "please input your name and password"
Require user admin
#Require valid-user #二者仅存一个
</Directory>
}
IP对应多个域名,通过域名访问IP
cd /var/www/html
ls
vim index.html
{
白茶清欢无别事
}
ls
pwd
ls
cd ..
mkdir /var/www/virtual/news/html -p
mkdir /var/www/virtual/music/html -p
vim /var/www/virtual/news/html/index.html
{
我的名字
}
cp /var/www/virtual/news/html/index.html /var/www/virtual/music/html
vim /var/www/virtual/music/html/index.html
{
初学者
}
cd /etc/httpd/conf.d/
vim 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>
}
vim news.conf
{
<VirtualHost *:80>
ServerName news.westos.com #此处为域名
DocumentRoot /var/www/virtual/news/html
Customlog logs/news.log combined
</VirtualHost>
<Directory "/var/www/vritual/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/vritual/music/html">
Require all granted
</Directory>
}
systemctl restart httpd
vim /etc/hosts
{
172.25.3.103 news.westos.com music.westos.com #此处域名应和上面的保持一致
}
测试:
在浏览器中:
输入 news.westos.com music.westos.com
访问php
vim /var/www/html/index.php
{
<?php
phpinfo();
?>
}
yum install php -y
systemctl restart httpd
###########cgi服务##############################################
cd /var/www/html
ls
mkdir cgi
cd /var/www/html/cgi
ls
vim index.cgi
{
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`; (此处不是单引号,而是波浪线键)
}
ls
chmod +x index.cgi
./index.cgi
vim /etc/httpd/conf.d/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>
}
systemctl restart httpd
测试:
浏览器中输入:
172.25.3.103/cgi/index.cgi
每刷新一次时间会更改一次
wsgi服务
yum install mod_wsgi -y #下载插件
cd /var/www
mkdir wsgi
cd wsgi
浏览器中输入:http://172.25.254.250/RHCEPACKAGES/
找到:materials/script.wsgi
复制脚本文件
或者:wget http://172.25.254.250/RHCEPACKAGES/materials/script.wsgi
vim script.wsgi
{
#!/usr/bin/env python
import time
def application (environ, start_response):
response_body = 'UNIX EPOCH time is now: %s\n' % time.time()
status = '200 OK'
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', '1'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)
return [response_body]
}
cd /etc/httpd/conf.d
vim vhost.conf
{
<VirtualHost *:80>
ServerName www.westoswsgi.com
WSGIScriptAlias / /var/www/wsgi/script.wsgi
</VirtualHost>
}
systemctl restart httpd
防火墙允许http https服务
vim /etc/hosts
{
172.25.3.103 www.westoswsgi.com
}
浏览器中输入: www.westoswsgi.com
https自签名证书
yum install -y mod_ssl #apache的ssl
systemctl restart httpd
yum install -y crypto-utils
genkey www.westos.com
vim /etc/httpd/conf.d/ssl.conf
{
101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
108 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
}
systemctl restart httpd
systemctl stop firewalld
网页重写
cd /etc/httpd/conf.d
cp news.conf login.conf
ls
vim login.conf
{
<VirtualHost *:443>
ServerName login.westos.com
DocumentRoot /var/www/virtual/login/html
Customlog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</VirtualHost>
<Directory "/var/www/vritual/login/html">
Require all granted
</Directory>
}
mkdir -p /var/www/virtual/login/html
vim /var/www/virtual/login/html/
vim /var/www/virtual/login/html/index.html
{
<h1>login page</h1>
}
systemctl restart httpd
vim login.conf
{
<VirtualHost *:80>
ServerName login.westos.com
RewriteEngine On
RewriteRule ^(/.*)$https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
}
vim /etc/hosts
{
172.25.3.103 login.westos.com
}
systemctl restart httpd
squid服务
yum install squid -y
vim /etc/squid/squid.conf
{
56 http_access allow all
60 http_port 80 vhost vport
63 cache_dir ufs /var/spool/squid 100 16 256
64 cache_peer 172.25.254.132 parent 80 0 proxy-only round-robin(轮回) originserver name=web1 weight=2(权重)
65 cache_peer 172.25.254.223 parent 80 0 proxy-only round-robin originserver name=web2
66 cache_peer_domain www.westos.com web1 web2
}
firewall -antlupe | grep squid
firewall-cmd --list-all
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
systemctl restart squid
vim /etc/hosts
{
172.25.254.251 www.westos.com
}
在浏览器中输入:www.westos.com
实现输出132和223之间的轮回显示
apache的论坛服务
yum install httpd -y
get Discuz_X3.2_SC_UTF8.zip
cd /var/www/html
unzip /root/ Discuz_X3.2_SC_UTF8.zip #解压文件
ls
cd readme
ls
less readme.txt
cd ..
cd upload
cd ..
cd upload/
ls
chmod o+w ./config/ -R
chmod o+w ./data/ -R
yum install php -y
systemctl restart httpd
yum install mariadb-server -y
vim /etc/my.cnf
{
skip-networking=1
}
systemctl restart mariadb
mysql_secure_installation
{
输入密码(redhat)
}
ls
cd ..
cd /etc/httpd/conf.d
ls
vim vhost.conf
{
<VirtualHost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.westosbbs.com
DocumentRoot /var/www/html/upload
CustomLog logs/bbs.log combined
</VirtualHost>
}
systemctl restart httpd
cd /var/www/html
ls
cd upload/
ls
chmod o+w uc_client/ uc_server -R
php -m
yum install php-mysql.x86_64 -y
systemctl restart httpd
mysql -uroot -predhat
cd /var/lib/mysql
cd /ultrax
ls
cd ultrax/
浏览器中输入:172.25.254.251/upload
进入论坛页面
yum install php-mysql.x86_64 -y #此处下载此文件
*
squid 正向代理 反向代理
#正向代理(实验条件:(真机)IP:172.25.254.4能上网;虚拟机IP:172.25.254.104不能上网;让虚拟机使用代理去联网)**
正向代理 是位于客户端和原始服务器之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端
前提条件真机能上网
1.把真实主机变成路由器
systemctl stop libvirtd
systemctl restart firewalld
systemctl start libvirtd
firewall-cmd --list
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload
firewall-cmd --list-all
public (default, active)
interfaces: br0 enp0s25 wlp3s0
sources:
services: dhcpv6-client ssh
ports:
masquerade: yes <<<地址伪装功能开启,真实主机变成路由器
forward-ports:
icmp-blocks:
rich rules:
2 yum install squid -y #下载squid
systemctl start squid #启动squid
vim /etc/squid/squid.conf
systemctl restart squid #重启squid服务
firewall-cmd --permanent --add-port=3128/tcp ##开启端口3128;代理端口是3128
firewall-cmd --reload ##刷新
3.配置虚拟机
4.测试
#此时可以连接百度,但是ping不同百度,此时访问的是百度的缓存服务
**反向代理:(实验条件:三台主机:客户端IP:172.25.254.104;代理端IP:172.25.254.204;服务端IP:172.25.254.4)**
反向代理方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器
1.服务端写好发布文件
cd /var/www/html
vim index.html
2.代理端
yum install squid.x86_64 -y
vim /etc/squid/squid.conf ##编辑配置文件
3.客户端
systemctl stop firewalld #关闭防火墙