LINUX----apache

一.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/*


二.apache部署:

1,配置网络
2,安装软件
yum install http.x86_64 -y  ------对外提供超文本协议,提供web服务器

 

3,开启火墙策略(火墙开启的情况下)
图形界面:firewall-config
permanent-----http-https---options----reload firewalld(重新加载火墙服务)


 

systemctl strat httpd
 systemctl enable httpd
---开机自启动


 查看: firewalld-cmd --list-all


4,默认接口---80
netstate -antlupe | grep http

5,默认文件:vim index.html默认目录: /var/www/html/

6,安装手册: yum install httpr-manual

7,在默认目录下编写默认文件,发布内容则发生变化
cd /var/www/html
vim index.html

测试:

 

 

三.修改接口:


A.vim /etc/httpd/conf/httpd.conf
(42)Listen 8080
  重新启动httpd


B.查看端口:netstat -antlupe | grep httpd

C.修改火墙策略
firewall-config
port---add--8080-add---6666--ok---options---reload
查看:firewalld-cmd --list-all


D.网页访问:172.25.254.120:8080即可


E.vim /etc/httpd/conf/httpd.conf
(42)Listen 6666


F.setenforce 0
systemctl restart httpd


G.查看允许默认接口,,,可见没有6666
srmanage port -l | grep htp


H.添加6666
semanage port -a -t http_port_t -p tcp 6666


I.测试:
172.25.254.120:6666即可看到

四.修改默认发布文件


A.cd /var/www/html/
   vim westos.html
 

B.systemctl restart httpd


C.修改配置文件默认的发布文件(可添加多个)
vim /etc/httpd/conf/httpd.conf
(164) westos.html


D.测试:172.25.254.120----显示的是westos.html 里面的内容


E.倘若删除westo.html
则看到的是 /var/www/html/里面的内容

 


五.修改默认查看目录


A.新建一个目录
  cd /var/www/html
  mkdir /westos/web/html -p

B.vim /westos/web/html/westos.html
  <h1>/westos/web/html's page</h1>

C.配置文件授权
vim /etc/httpd/conf/httpd.conf
注销119
120 DocumentRoot '/westos/web/html'
<Directory "/westos/web/html">
           Require all granted (所有人可见)

</Directory>
systemctl restart httpd

SELINUX---开启
D.semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'

 

E.rstorecon -RvvF /westos/


测试:172.25.254.120

*********************************************************************
六.配置apache虚拟主机

cd /var/www/
mkdir westos.com/news/html -p
mkdir westos.com/music/html -p
设定两个文件可看内容


A.vim westos.com/news/html/index.html
<h1> news's page</h1>


B.vim westos.com/music/html/index.html
<h1> music's page</h1>

编辑配置


cd /etc/httpd/conf.d/
1#vim a_default.conf
<VirtualHost _default_:80>
        DocumentRoot /var/www/html
        CustomLog logs/default.log combined
</VirtualHost>

 

2#vim news.conf

<VirtualHost *:80>
        ServerName news.westos.com
        DocumentRoot /var/www/westos.com/news/html  指定默认目录
        CustomLog logs/news.log combined 指定日志---便于排错
</VirtualHost>
<Directory"/var/www/westos.com/news/html">

<指定访问地址名称news.westos.com----指定目录/var/www/westos.com/news/html>
   Require all granted-----指定所有人可见
</Directory>

3#cp news.conf music.conf
    vim music.conf

<VirtualHost *:80>
        ServerName music.westos.com
        DocumentRoot /var/www/westos.com/music/html
        CustomLog logs/music.log combined
</VirtualHost>
<Directory"/var/www/westos.com/music/html">
       Require all granted
</Directory>


4,systemctl restart httpd
5.
本地解析---主机添加
vim /etc/hosts

 

测试:

 


七.apache访问控制

1,基于IP方式
#cd /etc/httpd/conf.d/
vim a_default.conf


<Directory "/var/www/html">
         Order Allow,Deny(谁在前先读取谁)
         Allow from all
         Deny from 172.25.254.220不允许220访问(先允许全部,再拒绝220)
</Directory>

systemctl restart httpd

20访问正常,


2,基于用户

A。创建认证文件
htpasswd -cm http_userlist admin


文件存在后,不加c
htpasswd -m http_userlist admin1


B。
vim  a_default.conf
前面ip注释掉
<Directory "/var/www/html">
         AuthUserFile /etc/httpd/conf.d/http_userlist---用指定文件做认证
        AuthName "Plase input username and passwd !!!"--用户可看到的标题
        AuthType basic---认证类型--基本认证。有密码即可
        #Require user admin
         Require vaild-user----指定可通过认证用户

</Directory>


清除内存:

C,ctrl+shift----everything

 

测试;

 

 

八.apache支持语言

 《一》PHP
1.cd /var/www/html
 vim index.php


 <?php
    phpinfo()
?>


2.yum install php -y


 php -a 可进入,说明安装成功

测试:172.25.254.120/index.php

《二》接口语言---cgi---通用网关接口
1.mkdir -p /var/www/html/cgi
2.semanager fcontent -a -t  httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'


3.restorecon -RvvF /var/www/html/cgi/

刷新SELINUX
 cd /var/www/html
4.vim cgi/index.cgi


#!usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;


5.cd /etc/httpd/conf.d/
vim a_default.conf
<Directory"/var/www/html/cgi">
       Options ExecCGI
       AddHandler cgi-script .cgi
</Directory>


6.chmod +x /var/www/html


测试:
172.25.254.120/cgi/index.cgi

《三》执行python语言

1.cd /var/www/
cd cgi-bin
rm -fr index.cgi

2.python webapp.wsgi  告诉系统webapp.wsgi是python语言
3.chmod +x webapp.wsgi 可执行权限


4.yum install mod_wsgi.x86_64


5.systemctl restart httpd
6.vim webapp.conf


<VirtualHost *:80>
        ServerName webapp.westos.com
        DocumentRoot /var/www/cgi-bin
        CustomLog logs/webapp.log combined
        WSGIScriptAlias / /var/www/cgi-bin/webapp.wsgi
</VirtualHost >

主机
vim /etc/hosts/
加上 webapp.westos.com

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
测试;

 

九.加密访问

1.yum install mod_ssl -y


2.yum install crypto-utils -y

3.genkey www.westos.com
next---1024---next


 

 

选择no

 

 

 

4.vim /etc/httpd/conf.d/ssl.conf
101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
109 SSLCertificateKeyFile /etc/pki/tls/private/


5,测试:
https:172.25.254.120

查看信息,是自己修改的内容

 

 

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
十.网页重写
一.制作一个虚拟主机
cd /var/www/
cd westos.com/
mkdir login
mkdir login/html


vim login/html/index.html
    <h1>login's page</h1>


二。网页重写
cd /etc/httpd/conf.d/
cp news.conf login.conf


vim login.conf
  1 <VirtualHost *:443>
  2         ServerName login.westos.com
  3         DocumentRoot /var/www/html/virtual/login.westos.com/html
  4         CustomLog "logs/login.logs" combined
  5         SSLEngine on
  6         SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
  7         SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
  8 </VirtualHost>
  9 <Directory "/var/www/html/virtual/login.westos.com/html">
 10         Require all granted
 11 </Directory>
 12 <VirtualHost *:80>
 13         ServerName login.westos.com
 14         RewriteEngine On
 15         RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
 16 </VirtualHost>


^(/.*)$  :客户在浏览器地址栏中输入的所有字符
ttps://   #强制客户加密访问

%{HTTP_HOST}    #客户请求主机

$1 # ‘$1标示^(/.*)$的值’
[redirect=301] #临时重写  301为永久转换

 测试

补充知识:

两种架构:
LAMP=linux + apache + mariadb + php
LAMP=linux + apache + mariadb + php/perl/python

十一.BBS论坛

 cd /var/www/
    cd /etc/http.conf.d/
    cp news.conf bbs.conf


   1. vim bbs.conf


  <VirtualHost *:80>
        ServerName   bbs.westos.com
        DocumentRoot /var/www/westos.com/bbs/html
        CustomLog    logs/bbs.log combined
</VirtualHost>
<Directory "/var/www/westos.com/bbs/html">
             Require all granted
</Directory>
                                  
 

   2. systemctl restart httpd


   3.mkdir /var/www/westos.com/bbs/html -p
    cd /var/www/westos.com/bbs/html
 

   4. unzip Discuz_X3.2_SC_UTF8.zip
   

   5. rm -fr Discuz_X3.2_SC_UTF8.zip
 

  cd /var/www/westos.com/bbs/html
  cd upload/
 
  6.  chmod -R 777 config


  7.  chmod -R 777 data

  8.  systemctl restart httpd
 9.  setenforce 0
   cd upload/


 10.  chmod 777 uc_client uc_server -R


 

11.  yum install mariadb-server -y
       

12.  systemctl start mariadb
 13.  systemctl enable mariadb


  14. vim /etc/my.cnf
  ( 10) skip-networking=1

 
 15. systemctl restart mariadb
  16.netstat -atnlupe | grep mysql
 17.mysql_secure_installation


  18  yum install php-mysql.x86_64  -y


 
    systemctl restart httpd

主机测试ho

vim /etc/hosts

 

 

论坛制作安成


十二.CDN加速=CONTENT DELIVERY NETWORK 内容发布网络
squid ---软件用于翻墙
 此实验172.25.254.120----用于客户端
       172.25.254.220---用于服务端

  服务端:
1.下载squid
   yum install squid -y


2.systemctl start squid
3.vim /etc/squid/squid.conf


(56)http_access allow all
(62)去掉注释


4.systemctl restart squid
5.systemctl syop firewalld


 

客户端:

本不可以上网设定:翻墙
1.打开firefox

 

2.edit---perferance---advanced-----network---settings---manual pro---
http proxy---172.25.254.220(服务端ip)---port---3128
-----use this    -----ok便可浏览百度信息

 

 

关闭翻墙
edit---perferance---advanced-----network---settings----no proxy

 


*******************************************************************
十三.反向代理

服务端
vim /etc/squid/squid.conf
(59)http_port 80 vhost vport
虚拟端口   虚拟域名
cache_peer 172.25.254.120 parent 80 0 proxy-only
       当你访问80端口时,我用100 的80端口做代理

 

systemctl restart squid

主机端


vim /etc/hosts
172.25.254.220

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
十四.轮循
服务端口:

vim /etc/squid/squid.conf
(60)cache_peer 172.25.254.120 parent 80 0 proxy-only name=web1 round-robin
(60)cache_peer 172.25.254.130 parent 80 0 proxy-only name=web2 round-robin
 cache_peer_domain web1 web2 www.westos.com
 

 

systemctl restart squid
客户端
主机测试

www.westos.com
120 和130的默认文件交相实现

 

 

 

8*******************************************************************
十五,权重
weght=N

服务端口:
vim /etc/squid/squid.conf
(60)cache_peer 172.25.254.120 parent 80 0 proxy-only name=web1 round-robin  weight=2
(60)cache_peer 172.25.254.130 parent 80 0 proxy-only name=web2 round-robin
 cache_peer_domain web1 web2 www.westos.com

 

 systemctl restart squid
客户端
主机测试

www.westos.com
120 和130的默认文件交相实现,120出现两次130出现一次

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值