Linux基础(五)-apache服务配置

#Linux阶段学习重点
1.Linux常用命令
2.Linux系统管理
3.Linux网络应用
4.LAMP产品级环境搭建
5.Apache服务器配置
6.LNMP环境快速部署-Nginx服务器配置

##目标
1.具有使用Linux系统进行开发的能力
2.进行Linux服务器常规管理运维


##第五天 Apache服务配置

###一. 世界使用量最高的web服务器 httpd

	url = http://www.sina.com.cn:80/admin/index.php


###二. 安装
1. LAMP源码包编译安装

	   生产环境  安全 稳定

	   开发环境

	2. 二进制包安装  yum 


###三. 相关文件

	配置文件
			/usr/local/apache2/etc/httpd.conf  主配置文件
			/usr/local/apache2/etc/extra/httpd-*.conf  子配置文件
			
	网站默认保存目录 /usr/local/apache2/htdocs/ 
	
	日志保存目录  /usr/local/apache2/logs/ 

	tail -f  access_log   动态查看文件内容
	
	日志处理:  access_log   error_log 
	
	vim /etc/logrotate.conf 
	
	 35 /usr/local/apache2/logs/access_log {
	 36     daily
	 37     rotate 30
     38 }
     39 
     40 /usr/local/apache2/logs/error_log {
     41     daily
     42     rotate 30
     43 }     

   logrotate -f /etc/logrotate.conf 手动执行文件 查看日志


###四. 配置文件

	命令别名   alias
	vim ~/.bashrc
	alias sto='/usr/local/apache2/bin/apachectl stop'
	alias sta='/usr/local/apache2/bin/apachectl start'

	source ~/.bashrc
	
	sto
	sta
	
	vim /usr/local/apache2/etc/httpd.conf

设置行号:vim /root/.vimrc

set nu

####实验1 目录别名 扩展网站目录 增加服务器

    1.修改主配置文件
      vim /usr/local/apache2/etc/httpd.conf
      453 Include etc//extra/httpd-autoindex.conf
    2.修改子配置文件
      vim /usr/local/apache2/etc/extra/httpd-autoindex.conf
       29 Alias /bbs/ "/usr/local/apache2/bbs/"
       30 
       31 <Directory "/usr/local/apache2/bbs/">
       32     Options Indexes
       33     Allowoverride None
       34     Require all granted
       35 </Directory>

	3.建立目录 /usr/local/apache2/bbs
	  mkdir  /usr/local/apache2/bbs/
	  vim index.html
	  
	4.重启服务  测试 
	
	  sto
	  sta 
	  
	  测试   192.168.184.252/bbs/
修改网站根目录
	DocumentRoot "/www"
	<Directory "/www">
	</Directory>

####实验2 虚拟主机

	1.域名解析   文件解析 
	  C:\Windows\System32\drivers\etc\hosts
	  192.168.184.252  www.sina.com
	  192.168.184.252  www.sohu.com
	  
	2.网站目录规划   
       mkdir  -p /share/sina    --  www.sina.com		
	   mkdir  /share/sohu       --  www.sohu.com
	   
	   vim /share/sina/index.html
	   vim /share/sohu/index.html
	   
	3.修改主配置文件
	  vim /usr/local/apache2/etc/httpd.conf
	  465 Include etc//extra/httpd-vhosts.conf
	  
	4.修改子配置文件
	  vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
	   23 <Directory "/share/sina">
       24     Options Indexes
       25     AllowOverride None
       26     Require all granted
       27 </Directory>
       28     
       29 <Directory "/share/sohu">
       30     Options Indexes
       31     AllowOverride None
       32     Require all granted
       33 </Directory> 
       34     
       35 <VirtualHost 192.168.184.252>
       36     ServerAdmin webmaster@sina.com
       37     DocumentRoot "/share/sina/"
       38     ServerName www.sina.com
       39     ErrorLog "logs/sina-error_log"
       40     CustomLog "logs/sina-access_log" common
       41 </VirtualHost>
       42 
       43 <VirtualHost 192.168.184.252>
       44     ServerAdmin webmaster@sohu.com
       45     DocumentRoot "/share/sohu/"
       46     ServerName www.sohu.com
       47     ErrorLog "logs/sohu-error_log"
       48     CustomLog "logs/sohu-access_log" common
       49 </VirtualHost>

	5. 重启服务  测试
	sto
	sta
	
	测试  www.sina.com   www.sohu.com

####实验3 rewrite 重写/重定向

	  www.sina.com  -> www.sohu.com

	  1.修改主配置文件
	    vim /usr/local/apache2/etc/httpd.conf
	    147 LoadModule rewrite_module modules/mod_rewrite.so
	  2.修改子配置文件(虚拟主机文件)
	    vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
	     23 <Directory "/share/sina">
         24     Options Indexes FollowSymLinks
         25     AllowOverride All 
         26     Require all granted
         27 </Directory>

	  3. 建立权限文件.htaccess
	    vim /share/sina/.htaccess
	      1 RewriteEngine on
          2 RewriteCond %{HTTP_HOST} www.sina.com
          3 RewriteRule .* http://www.sohu.com

	  4. 重启服务  测试
	  	sto
	  	sta
	  	
	  	测试  www.sina.com -> www.sohu.com


 	网页文件跳转 
 		1.修改权限文件
 		vim  /share/sina/.htaccess
 		  1 RewriteEngine on
		  2 RewriteRule index(\d+).html  index.php?id=$1
		  
		2.建立 index.php 文件
		vim /share/sina/index.php
		<?php   echo "hello  reWrite"; ?>
		
	    重启服务  测试
	    sto 
	    sta  
	    
	    测试   www.sina.com/index5.html
阿里云 (腾讯云 百度云 华为云 aws (亚马逊云) 微软云)
域名  租用 
云服务器ECS   实例选择   镜像选择    扩容





###作业

	所有的实验 至少三遍!

	思考题  怎样做到  192.168.184.252   正常访问 /usr/local/apache2/htdocs/
	                 sina  sohu        
















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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值