一、http服务配置
curl -I www.baidu.com 查看配置
yum install httpd
systemctl start httpd
systemctl stop firewalld
netstat -antlupe | grep httpd
cd /var/www/html
vim index.html
<h1>hello world </h1>
浏览器输入172.25.254.109默认读取index.html的内容
vim test.html
<h1> westos </h1>
浏览器输入172.25.254.109/test.html
http中/ 相当于/var/www/html
ftp中/ 相当于 /var/ftp
(1)端口的设置
vim /etc/httpd/conf/httpd.conf
Listen 8080 将之前端口80改为8080
systemctl restart httpd
netstat -antlupe | grep httpd
浏览器输入 172.25.254.109:8080
vim /etc/httpd/conf/httpd.conf
Listen 80 将之前端口8080改为80
systemctl restart httpd
netstat -antlupe | grep httpd
(2) http下默认目录和默认文件的配置
mkdir /westos/html -p
cd /westos/html
vim index.html
编辑westos
vim test.html
编辑linux
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html" 注释掉原先的默认目录
DocumentRoot "/westos/html"默认目录为/westos/html
<Directory "/westos">
require all granted
DirectoryIndex test.html
</Directory>
浏览器输入172.25.254.109 出现test.html的内容
<Directory "/westos/html/linux">
DirectoryIndex index.html
</Directory>
cd /westos/html
mkdir linux
vim index.html
123
vim test.html
234
<Directory "/westos/html/linux">
DirectoryIndex index.html
</Directory>
浏览器上输入172.25.88.56/linux 输出linux下的index.html的内容
浏览器上输入172.25.88.56/linux/test.html 输出linux下的test.html的内容
当注释掉<Directory "/westos/html/linux">
DirectoryIndex index.html
</Directory>
浏览器上输入172.25.88.56/linux 输出linux下的test.html的内容
<Directory "/westos">
require all granted
DirectoryIndex test.html
</Directory>
读取这段内容 对于/westos/html的文件的内容都生效
(3)基于ip的访问控制
cd /var/www/html
mkdir westos
vim index.hml
<h1> wangning </h1>
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">
order Allow,deny 改变黑白名单后需要改变先后顺序
Allow from 172.25.88.250 先读取白名单,再读取黑名单
Deny from All
</Directory>
systemctl restart httpd
浏览器输入172.25.88.250/westos
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">
order deny,Allow 改变黑白名单后需要改变先后顺序
Deny from All
Allow from 172.25.88.250 先读取黑名单,再读取白名单
</Directory>
systemctl restart httpd
(4)基于用户的访问控制
cd /etc/httpd
htpasswd -cm apacheuser admin -c表示新建
htpasswd -m apacheuser tom 添加用户,如果有-c,则会被覆盖
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">
AuthUserFile /etc/httpd/apacheuser
AuthName "please input user and password!!"
AuthType basic
# Require user tom 特殊指定用户,注释掉则读取下面所有用户登录信息
Require valid-user 允许文件里所有用户登陆
</Directory>
(5).apache的虚拟主机
浏览器所在主机上
vim /etc/hosts
172.25.254.109 www.westos.com news.westos.com music.westos.com
cd /etc/httpd/conf.d
vim default.conf
<VirtualHost _default_:80>
DocumentRoot "/var/www/html"
CustomLog "logs/default.log" combined
</VirtualHost>
vim news.conf
<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot "/var/www/virtual/westos.com/news/"
CustomLog "logs/news.log" combined
</VirtualHost>
<Directory "/var/www/virtual/westos.com/news/">
Require all granted
</Directory>
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>
mkdir -p /var/www/virtual/westos.com/news
mkdir -p /var/www/virtual/westos.com/music
cd /var/www/virtual/westos.com/music
vim index.html
music'page
cd /var/www/virtual/westos.com/newsfg
vim index.html
news'page
测试
浏览器:www.westos.com 输出hello world
news.westos.com 输出news'page
music.westos.com 输出music'page
(6)安全证书的建立
yum install mod_ssl -y
ls /etc/httpd/conf.d
yum install crypto-utils -y
genkey www.westos.com
设置信息
CN
shannxi
xi'an
westos
linux
生成证书和密钥
vim /etc/httpd/conf.d/ssl.conf
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key注释
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
#SSLCertificateFile /etc/pki/tls/certs/localhost.cr 注释掉以前的 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
systemctl restart httpd
在浏览器中点击perference设置->Anvanced->view certificates->servers(删除本机服务)如果不存在则直接输入
浏览器输入 https:// www.westos.com 点击I understand the Risks 下载内容,然后查看
点击浏览器编辑框锁子->more information(进行证书的查看)
(6)对特定目录自动生成安全锁和密钥
cd /etc/httpd/conf.d
vim login.conf
<VirtualHost *:443>
ServerName login.westos.com
DocumentRoot "/var/www/virtual/westos.com/login/"
CustomLog "logs/login.log" combined
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
</VirtualHost>
<Directory "/var/www/virtual/westos.com/login/">
Require all granted
</Directory>
<VirtualHost *:80>
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
mkdir -p /var/www/virtual/westos.com/login
vim index.html
login.pages
浏览器 login.westos.com
(7)php下特定目录cgi自动启动命令
yum install php
cd /etc/httpd/conf.d
vim php.conf
DirectoryIndex index.php index.html
cd /var/www/html/
vim index.php
<?php
phpinfo();
?>
systemctl restart httpd
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
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
DirectoryIndex index.cgi
</Directory>
chmod +x /var/www/html/cgi/index.cgi
浏览器输入172.25.88.56/cgi/index.cgi
输出时间
8搭建论坛
cd /var/www/html
Discuz_X3.2_SC_UTF8.zip
解压:unzip Discuz_X3.2_SC_UTF8.zip
chmod 777 /var/www/html/upload/ -R
mysql -uroot -plinux
yum install php-mysql.x86_64
systemctl start mariadb
systemctl restart httpd
浏览器输入 172.25.88.56/upload
输入用户和密码,登陆论坛
9:正向代理
服务器:(172.25.88.250)
yum install squid
vim /etc/squid/squid.conf
http_access allow all
# Squid normally listens to port 3128
http_port 3128
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256
测试机:(172.25.88.56)
浏览器-> perference->advance->network->settings->manual proxy configuration:
HTTP proxy:172.25.88.250 3128
浏览器输入:www.baidu.com
squid 反向代理
一台主机(172.25.88.56):
yum install squid
vim /etc/squid/squid.conf
http_port 80 vhost vport
cache_peer 172.25.88.250 parent 80 0 proxy-only
cache_dir ufs /var/spool/squid 100 16 256
一台主机(172.25.88.250)apache
yum install httpd
vim /var/www/html/index.html
<h1> hello world </h1>
测试主机
浏览器输入172.25.88.56 输出109的文件