Apache

curl -I www.baidu.com    他的服务是用Apache源码自己开发的  curl联网才能用

搜狐用的nginx  腾讯用的是squidCDN加速)

 

Apache http协议共享文件

互联网主流web引擎有 Apache nginx

 

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Apache的安装

yum install -y httpd

systemctl start httpd

systemctl enable httpd

systemctl stop firewalld

systemctl disable firewalld

 

Apache信息

1 apache的默认发布文件  index.html

2 apache的配置文件

/etc/httpd/conf/httpd.conf  主配置文件

/etc/httpd/conf.d/*.conf    子配置文件

3 apache的默认发布目录 /var/www/html

4 apache的默认端口 80

 

apache的基本配置

1修改默认发布文件

vim /etc/httpd/conf/httpd.conf

164  DirectoryIndex westos.html    index.html修改成westos.html

index.html   westos.html里面分别写hello world  lala 做测试页

systemctl restart httpd

 

2修改默认发布目录

##selinuxdisable状态

vim /etc/httpd/conf/httpd.conf

120  DocumentRoot "/westos/www/test"  注释掉上一行DocumentRoot"/var/www/html"

<Directory "/westos/www/test">

Require all granted

</Directory>

mkdir -p /westos/www/test

systemctl restart httpd  

这是默认目录就改成了 /westos/www/test

 

apache的访问控制

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin">    

order Allow,Deny

Allow from All

Deny from 172.25.254.250

</Directory>

允许所有人访问admin目录 但不允许172.25.254.250访问

 

<Directory "/var/www/html/admin">    

    order DenyAllow    先读deny语句

    Allow from 172.25.254.250

    Deny from All

</Directory>

只允许172.25.254.250访问

 

设定用户的访问

htpasswd -m /etc/httpd/accessuser admin

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin">

AuthUserFile /etc/httpd/accessuser     用户认证文件

AuthName "Please input your name and password!!"  用户认证提示信息

AuthType basic    认证类型

Require valid-user 认证用户,认证文件中所用用户都可以访问

[Require user admin] 只允许认证文件中admin用户可以访问

systemctl restart httpd  这是时出现一个认证窗口 输入用户和密码之后才可以看到默认界面@@@@@@@@@@ Apache 的虚拟主机  @@@@@@@@@@@@

1 定义

可以让我们的一台apache服务器在被访问不同域名的时候可以显示不同的页面

(比如腾讯的一台apache服务器挂了多个站点 news.qq.com money.qq.com www.qq.com  访问这三个不同的域名分别出现新闻 财经 和主页面 但这三个页面的是一样的 即一台apache服务器再被访问不同域名时会出现不同的页面)

 

2 建立测试页

mkdir /var/www/virtual/money.westos.com/html -p

mkdir /var/www/virtual/news.westos.com/html -p

echo "money.westos.com's page">/var/www/virtual/money.westos.com/html/index.html

echo "news.westos.com's page">/var/www/virtual/news.westos.com/html/index.html

## echo 是写测试页面

 

配置

vim /etc/httpd/conf.d/default.conf  未指定域名的访问都访问default

<Virtualhost   _default_:80>        虚拟主机开启的端口80

    DocumentRoot "/var/www/html"虚拟主机的默认发布目录

    CustomLog "logs/default.log" combined 虚拟主机日志 combined记录所有日志

</Virtualhost>

 

vim /etc/httpd/conf.d/money.conf指定域名money.westos.com的访问都到指定默认发布目录中

<Virtualhost *:80>

    ServerName "money.westos.com"

    DocumentRoot "/var/www/virtual/money.westos.com/html"

    CustomLog "logs/news.log" combined

</Virtualhost>

<Directory "/var/www/virtual/money.westos.com/html">  对默认发布目录授权

    Require all granted  给目录做访问授权 不然输域名是找不到指定目录的 所有人访问

</Directory>             这个目录都有权限

 

vim /etc/httpd/conf.d/news.conf

 29 <Virtualhost *:80>

 30     ServerName "news.westos.com"

 31     DocumentRoot "/var/www/virtual/news.westos.com/html"

 32     CustomLog "logs/news.log" combined

 33 </Virtualhost>

 34 <Directory "/var/www/virtual/news.westos.com/html">

 35     Require all granted

 36 </Directory>

 

4测试

在浏览器所在主机中 vim /etc/hosts 做域名解析

www.westos.com money.westos.com news.westos.com

在浏览器上输www.westos.com会看到他的测试页面 输menoy.westos.com会看到money.westos.com's page 字样 输news.westos.com 会看到news.westos.com字样的页面

 

 

@@@@@@@@@@@@@@@  https  @@@@@@@@@@@@@@@@

1 https定义

Hyper text transter protocol over secure socker layer

通过ssl

 

http(明文访问) https(加密访问) (银行优盾是加密的,将数据包加密发送到银行服务器 银行在解密看数据包 防止抓包 放置信息泄露 用锁加密用证书解密 )

http-https 端口由80变成443 需要ssl插件

2 配置

yum install -y mod_ssl crypto-utils

genkey www.westos.com   给自定义的页面加锁成https

/etc/pki/tls/private/www.westos.com.key

/etc/pki/tls/cert/www.westos.com.crt  

产生一个钥匙和一个证书

 

vim /etc/httpd/conf.d/login.conf

<Virtualhost *:443>

        ServerName "login.westos.com"

        DocumentRoot "/var/www/virtual/login.westos.com/html"

        CustomLog "log/login.log" combined

        SSLEngine on 开启https功能

        SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt 证书

        SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key 密钥

</Virtualhost>

<Directory "/var/www/virtual/login.westos.com/html">

        Require all granted

</Directory>

<Virtualhost *:80>  网页重写实现自动访问https

        ServerName login.westos.com

        RewriteEngine on

        RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

</Virtualhost>

 

注释:

RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

^(/.*)$   客户主机在地址栏中写入的所有字符,不好看换行符

https://  定向成为的访问协议

%{HTTP_HOST} 客户请求主机

$1           $1的值就表示^(/.*)$的值

[redirect=301]临时重定向 302永久重定向

 

mkdir /var/www/virtual/login.westos.com/html -p

vim /var/www/virtual/login.westos.com/html/index.html

写测试页 login.westos.com

systemctl restart httpd

 

测试:

在客户端主机添加解析   

vim /etc/hosts    172.25.254.70  login.westos.com

 

访问http://login.westos.com 会自动跳转到

https://login.westos.com 实现页面数据加密传输


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章