apache服务测试
2021-05-18 22:33
标签:md5 manage word stp load epo 密钥 密码 作用 实验一、安装apache,并提供服务 实验二、软链接网站 在RHEL2的浏览器访问测试: 实验三、基于域名的虚拟主机 #默认网站/var/www/html的配置 #域名www.lxj.com的配置 #域名www.lxj2.com的配置 #systemctl restart httpd 在RHEL2的浏览器访问测试: 说明:必须配置DNS域名解析。请参考http://www.cnblogs.com/rusking/p/7581877.html 实验四、基于IP的虚拟主机 添加配置文件,并配置网络参数 [root@rhel1 ~]# mkdir /var/www/test11 systemctl restart httpd 在RHEL2的浏览器访问测试: [root@rhel1 ~]# mkdir /var/www/testport8888 #直接修改上面的配置文件11.conf来进行测试 #systemctl restart httpd 在RHEL2的浏览器访问测试: 在RHEL2的浏览器访问测试: 实验七、Alias # vi /etc/httpd/conf.d/0.conf 访问测试: 实验八-调用脚本 vim /var/www/cgi-bin/perl.pl yum install -y mod_wsgi #apache调用python脚本时需要用到这个模块 vim /var/www/cgi-bin/python.py def application (environ, start_response): chmod a+x /var/www/cgi-bin/shell.sh vim /etc/httpd/conf.d/testscript.conf systemctl restart httpd 访问测试: 实验九-拒绝访问 systemctl restart httpd 测试: Order deny,allow 之后,再该目录下生成两个文件:证书 lxjtest.crt 和密钥 lxjtest.key yum install -y mod_ssl.x86_64 #安装ssl模块 vim /etc/httpd/conf.d/ssl.conf firewall-cmd --permanent --add-service=https mkdir /var/www/443 vim /etc/httpd/conf.d/0.conf vim /etc/httpd/conf.d/443.conf #增加加密的www.rusky.com网站,新增行可用cat /etc/httpd/conf.d/ssl.conf | grep ^SSL | tail -n 5获得 在RHEL1和RHEL2上 访问测试: 实验十一、访问http网站自动转为https 访问测试: apache服务测试 标签:md5 manage word stp load epo 密钥 密码 作用 原文地址:http://www.cnblogs.com/rusking/p/7723676.html
在RHEL1上
#yum install -y httpd
#echo basictest > /var/www/html/index.html
#systemctl restart httpd
#systemctl enable httpd
#netstat -anplut| grep httpd
#firewall-cmd --permanent --add-service=http
#firewall-cmd --reload
在RHEL2的浏览器访问测试:
http://192.168.100.1
#mkdir /local
#echo lxjtest > /local/index.html
#semanage fcontext -a -t httpd_sys_content_t ‘/local(/.*)?‘
#restorecon -vvFR /local
#ln -s /local/ /var/www/html/soft
http://192.168.100.1/soft
#vi /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf #模板---下面的内容,可以从模板中copy内容
# mkdir /var/www/lxj
# mkdir /var/www/lxj2
# echo lxj1 >/var/www/lxj/index.html
# echo lxj2 >/var/www/lxj2/index.html
# vi /etc/httpd/conf.d/0.conf
ServerAdmin root@rusky.com
DocumentRoot "/var/www/html"
ServerName www.rusky.com
ErrorLog "/var/log/httpd/192.168.100.1-error_log"
CustomLog "/var/log/httpd/192.168.100.1-access_log" comon
# vi /etc/httpd/conf.d/lxj.conf
ServerAdmin root@ruksy.com
DocumentRoot "/var/www/lxj"
ServerName www.lxj.com
Errorlog "/var/log/httpd/www.lxj.com-error_log"
CustomLog "/var/log/httpd/www.lxj2.com-access_log" common
# cp /etc/httpd/conf.d/lxj.conf /etc/httpd/conf.d/lxj2.conf
# vi /etc/httpd/conf.d/lxj2.conf
ServerAdmin root@ruksy.com
DocumentRoot "/var/www/lxj2"
ServerName www.lxj2.com
Errorlog "/var/log/httpd/www.lxj2.com-error_log"
CustomLog "/var/log/httpd/www.lxj2.com-access_log" common
http://www.rusky.com/ --默认网站,内容为basictest
http://www.lxj.com --lxj网站,内容为lxj
http://www.lxj2.com --lxj2网站,内容为lxj2
或者如果你不想配置DNS域名解析,你可以直接修改物理机C:\Windows\System32\drivers\etc\hosts文件,添加如下内容:
192.168.100.1 www.rusky.com
192.168.100.1 www.lxj.com
192.168.100.1 www.lxj2.com
这样,你的物理机就可以ping通上面三个域名了,你可以直接使用物理机的浏览器来进行访问测试。
添加一块网卡,设置IP为192.168.100.11/24
[root@rhel1 ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
virbr0 46056c19-c40a-40cc-a0c5-296cf7049362 bridge virbr0
[root@rhel1 ~]# nmcli device show | grep -i device
GENERAL.DEVICE: virbr0
GENERAL.DEVICE: enp0s3
GENERAL.DEVICE: enp0s8
GENERAL.DEVICE: lo
GENERAL.DEVICE: virbr0-nic
添加了一块网卡enp0s8。
[root@rhel1 ~]# nmcli connection add type ethernet con-name enp0s8file ifname enp0s8
[root@rhel1 ~]# nmcli connection modify enp0s8file ipv4.method manual ipv4.addresses 192.168.100.11/24 ipv4.gateway 192.168.100.100 autoconnect yes ipv4.dns 192.168.100.1
[root@rhel1 ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 59118063-4e4e-403c-ad25-374704d6f6f1 802-3-ethernet enp0s3
enp0s8file 982798e1-2f91-43f1-9644-5d0ea9839440 802-3-ethernet enp0s8
virbr0 46056c19-c40a-40cc-a0c5-296cf7049362 bridge virbr0
[root@rhel1 ~]# nmcli connection down enp0s8file
[root@rhel1 ~]# nmcli connection up enp0s8file
[root@rhel1 ~]# vi /etc/httpd/conf.d/11.conf
DocumentRoot "/var/www/test11" --其它参数可以不写,有这两行参数就可以了。
ServerName 192.168.100.11
[root@rhel1 ~]# echo test11 >/var/www/test11/index.html
http://192.168.100.1 ---访问默认网站,显示basictest内容
http://192.168.100.11 ---访问test11网站,显示 test11 内容。
实验五、基于端口的虚拟主机
[root@rhel1 ~]# semanage port -l | grep http
http_cache_port_t tcp 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
[root@rhel1 ~]# semanage port -a -t http_port_t -p tcp 8888
[root@rhel1 ~]# firewall-cmd --add-port=8888/tcp --permanent
[root@rhel1 ~]#firewall-cmd --reload
[root@rhel1 ~]#vi /etc/httpd/conf/httpd.conf
Listen 8888 #增加一行
[root@rhel1 ~]# echo 88888888 >/var/www/testport8888/index.html
[root@rhel1 conf.d]# vi 11.conf
ServerAdmin root@ruksy.com
DocumentRoot "/var/www/test11"
ServerName 192.168.100.11
ServerAdmin root@ruksy.com
DocumentRoot "/var/www/testport8888"
ServerName 192.168.100.11
http://192.168.100.1 ---默认80端口,显示test11内容。
http://192.168.100.11:8888 --显示内容为:88888888
实验六、LAMP
yum install -y php* mariadb*
unzip Discuz.zip ---http://www.discuz.net/forum.php 开源的PHP论坛
cp -rf upload/* /var/www/Discuz/
semanage fcontext -l | grep http | grep rw
chcon -R -t httpd_sys_rw_content_t /var/www/Discuz/
chown -R apache:apache /var/www/Discuz/
systemctl restart mariadb
systemctl enable mariadb
mysqladmin -u root password ‘123456‘
systemctl restart httpd
http://192.168.100.1/Discuz #需要输入数据库密码123456,更改表前缀
还原RHEL1虚拟机到初始化环境。
mkdir /var/www/lxj
mkdir /var/www/lxj2
echo lxj11111 >/var/www/lxj/index.html
echo lxj22222 >/var/www/lxj2/index.html
Servername 192.168.100.1
Documentroot /var/www/lxj
Alias /lxj2 /var/www/lxj2
AllowOverride none #增加,不允许覆盖写入
Require all granted #增加,允许所有人访问
http://192.168.100.1
结果:进入默认网站,显示内容为lxj11111
http://192.168.100.1/lxj2
结果:进入lxj2目录,显示内容为lxj22222
创建三个测试脚本:shell.sh,perl.pl,python.py
vim /var/www/cgi-bin/shell.sh
#!/bin/bash
echo -en "Content-Type: text/html; charset=UTF-8\n\n";
date +%c
#注意复制时可能会自动生成#
#!/usr/bin/perl
print "Content-Type: text/html; charset=UTF-8\n\n";
$now=localtime();
print "$now\n";
#注意复制时可能会自动生成#
#!/usr/bin/env python
import time
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]
chmod a+x /var/www/cgi-bin/perl.pl
#shell和pear必须有执行权限,python调用模块可以不加执行权限
ServerAdmin root@rusky.com
DocumentRoot /var/www/html
ServerName 192.168.100.1
ErrorLog "/var/log/httpd/192.168.100.1-error_log"
CustomLog "/var/log/httpd/192.168.100.1-access_log" common
ScriptAlias /jiaoben/ "/var/www/cgi-bin/" #增加,支持shell和perl。 /jiaoben是虚拟目录,对应后面的脚本所在的目录
WSGIScriptAlias /python /var/www/cgi-bin #增加,支持python。/python也是虚拟目录
http://192.168.100.1/jiaoben/perl.pl
http://192.168.100.1/jiaoben/shell.sh
http://192.168.100.1/python/python.py
vim /etc/httpd/conf.d/testscript.conf --添加如下内容
order allow,deny #顺序:先允许,再拒绝
allow from all
deny from 192.168.100.2 #网段采用192.168.100
192.168.100.2 不可以访问http://192.168.100.1/index.html,其他机器都可以访问
一些例子
Order deny,allow //默认充许所有主机访问
Deny from 192.168.0.100 //单独禁止
allow from all
deny from 219.204.253.8
#全部都可以通行
-------------------------------
Order deny,allow
deny from 219.204.253.8
allow from all
#全部都可以通行
-------------------------------
Order allow,deny
deny from 219.204.253.8
allow from all
#只有219.204.253.8不能通行
-------------------------------
Order allow,deny
allow from all
deny from 219.204.253.8
#只有219.204.253.8不能通行
-------------------------------
-------------------------------
Order allow,deny
deny from all
allow from 219.204.253.8
#全部都不能通行
-------------------------------
Order allow,deny
allow from 219.204.253.8
deny from all
#全部都不能通行
-------------------------------
Order deny,allow
allow from 219.204.253.8
deny from all
#只允许219.204.253.8通行
-------------------------------
Order deny,allow
deny from all
allow from 219.204.253.8
#只允许219.204.253.8通行
-------------------------------
--------------------------------
Order deny,allow
#全部都可以通行(默认的)
-------------------------------
Order allow,deny
#全部都不能通行(默认的)
-------------------------------
Order allow,deny
deny from all
#全部都不能通行
-------------------------------
Order deny,allow
deny from all
#全部都不能通行
-------------------------------
对于上面两种情况,如果换成allow from all,则全部都可以通行!
-------------------------------
Order deny,allow
deny from 219.204.253.8
#只有219.204.253.8不能通行
-------------------------------
Order allow,deny
deny from 219.204.253.8
#全部都不能通行
-------------------------------
Order allow,deny
allow from 219.204.253.8
#只允许219.204.253.8通行
-------------------------------
Order deny,allow
allow from 219.204.253.8
#全部都可以通行
实验十、SSL加密
在RHEL1上制作用于认证网站的证书和key
cd /etc/pki/tls/certs
make lxjtest.crt
Enter pass phrase: #输入123.com
Verifying - Enter pass phrase: #输入123.com
Enter pass phrase for lxjtest.key: #输入123.com
Country Name (2 letter code) [XX]: #输入CN
State or Province Name (full name) []: #输入BEIJING
Locality Name (eg, city) [Default City]: #输入BEIJING
Organization Name (eg, company) [Default Company Ltd]: #输入REDHAT
Organizational Unit Name (eg, section) []: #输入WEB
Common Name (eg, your name or your server‘s hostname) []: #输入www.rusky.com
cp lxjtest.key /etc/pki/tls/private/lxjtest.key
#相当于已经有了CA中心,并且CA中心已经颁发了证书lxjtest.crt,一般证书保存在certs文件夹下,密钥保存在private文件夹下
httpd -M | grep -i mod_ssl #查看apache加载的模块
#如果报错AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this message,一般是域名解析的错误,可以添加hosts记录,或者添加DNS记录,并更改配置文件的ServerName内容
SSLEngine off #更改,今后使用对每个网站的单独引擎
firewall-cmd --reload
echo html > /var/www/html/index.html
echo 443 > /var/www/443/index.html
cat /etc/httpd/conf.d/ssl.conf | grep -i ^ssl #复制尾部5行
DocumentRoot /var/www/html
ServerName www.rusky.com
DocumentRoot /var/www/443
ServerName www.rusky.com #必须和证书输入的域名一致
SSLEngine on #激活引擎
SSLProtocol all -SSLv2 -SSLv3 #除了-SSLv2和-SSLv3协议,这两个协议不安全。
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile /etc/pki/tls/cert/lxjtest.crt #证书位置
SSLCertificateKeyFile /etc/pki/tls/private/lxjtest.key #密钥位置
vim /etc/hosts
192.168.100.1 www.rusky.com
http://www.rusky.com/
https://www.rusky.com/
# vi 443.conf
Servername www.rusky.com
Documentroot /var/www/html
RewriteEngine on
RewriteRule ^/(.*) https://%{HTTP_HOST}$1 [L]
DocumentRoot /var/www/443test
ServerName www.rusky.com
SSLEngine on
SSLProtocol all -SSLv2 -SSLV3
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/lxjtest.crt
SSLCertificateKeyFile /etc/pki/tls/private/lxjtest.key
http://www.rusky.com #自动重定向为https://www.rusky.com
上一篇:jsp实现html页面静态化
下一篇:php单例模式