第五天 Apache服务配置
一.简介
世界使用率最高的web服务器(web server)
www world wide webe
http 超文本传输协议
html 超文本标记语言
URL 统一资源定位符 http://www.sina.com.cn:80/admin/index.php
https:// ssl :443
协议 域名(主机名) 端口 目录/文件
二.安装(LAMP)
1.LAMP源码包安装 生产环境(主要使用)
2.二进制包LAMP环境 (用于开发环境 少数生产环境)
三.相关文件(源码包)
配置文件 /usr/local/apache2/etc/httpd.conf
子配置文件 /usr/local/apache2/etc/extra/httpd-*
默认网站根目录 /usr/local/apache2/htdocs/
日志保存位置 /usr/local/apache2/logs/
access_log 访问日志
error_log 错误日志
tail -f access_log 动态查看文件内容
日志处理(日志切割轮替)
vim /etc/logrotate.conf
/usr/local/apache2/logs/access_log {
daily
rotate 30
}
/usr/local/apache2/logs/error_log {
daily
rotate 30
}
测试 logrotate -f /etc/logrotate.conf 手动执行 日志处理
ls /usr/local/apache2/logs/
四.配置文件
命令别名 alias
vim /root/.bashrc
alias sto='/usr/local/apache2/bin/apachectl stop'
alias sta='/usr/local/apache2/bin/apachectl start'
source /root/.bashrc 执行
测试
sto
sta
设置行号
vim /root/.vimrc
set nu
实验1. 目录别名 Alias 扩容网站 增加服务器
1)建立bbs目录
mkdir /usr/local/apache2/bbs/
vim /usr/local/apache2/bbs/index.html
hello Alias!
2)修改配置文件
vim /usr/local/apache2/etc/httpd.conf
453 Include etc//extra/httpd-autoindex.conf
3)修改子配置文件
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>
4)重启服务 测试
sto
sta
测试 192.168.5.5/bbs/
实验2.虚拟主机
1)域名解析
C:\Windows\System32\drivers\etc\hosts
192.168.5.5 www.sina.com
192.168.5.5 www.sohu.com
2) 规划网站目录
mkdir -p /share/sina/
mkdir /share/sohu/
vim /share/sina/index.html
Sina!
vim /share/sohu/index.html
Sohu!
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
24 <Directory "/share/sina/">
25 Options Indexes
26 AllowOverride None
27 Require all granted
28 </Directory>
29
30 <Directory "/share/sohu/">
31 Options Indexes
32 AllowOverride None
33 Require all granted
34 </Directory>
35 <VirtualHost 192.168.5.5>
36 ServerAdmin [email protected]
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.5.5>
44 ServerAdmin [email protected]
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 (301永久重定向)
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
24 <Directory "/share/sina/">
25 Options Indexes FollowSymLinks
26 AllowOverride All
27 Require all granted
28 </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
1 <?php
2 echo "hello world!";
3 ?>
3)重启 测试
sto
sta
测试 www.sina.com/index7.html
云计算 云服务器 AWS 阿里云 腾讯云 百度云 华为云
阿里 云服务器 ECS
域名购买
服务器 购买 设置 登录
搭建LAMP架构
上线 windows->linux 1. 代码文件 上传到 linux服务器 2.数据库导入到linux服务器数据库上 3.配置文件 测试 (上线成功)
一.简介
世界使用率最高的web服务器(web server)
www world wide webe
http 超文本传输协议
html 超文本标记语言
URL 统一资源定位符 http://www.sina.com.cn:80/admin/index.php
https:// ssl :443
协议 域名(主机名) 端口 目录/文件
二.安装(LAMP)
1.LAMP源码包安装 生产环境(主要使用)
2.二进制包LAMP环境 (用于开发环境 少数生产环境)
三.相关文件(源码包)
配置文件 /usr/local/apache2/etc/httpd.conf
子配置文件 /usr/local/apache2/etc/extra/httpd-*
默认网站根目录 /usr/local/apache2/htdocs/
日志保存位置 /usr/local/apache2/logs/
access_log 访问日志
error_log 错误日志
tail -f access_log 动态查看文件内容
日志处理(日志切割轮替)
vim /etc/logrotate.conf
/usr/local/apache2/logs/access_log {
daily
rotate 30
}
/usr/local/apache2/logs/error_log {
daily
rotate 30
}
测试 logrotate -f /etc/logrotate.conf 手动执行 日志处理
ls /usr/local/apache2/logs/
四.配置文件
命令别名 alias
vim /root/.bashrc
alias sto='/usr/local/apache2/bin/apachectl stop'
alias sta='/usr/local/apache2/bin/apachectl start'
source /root/.bashrc 执行
测试
sto
sta
设置行号
vim /root/.vimrc
set nu
实验1. 目录别名 Alias 扩容网站 增加服务器
1)建立bbs目录
mkdir /usr/local/apache2/bbs/
vim /usr/local/apache2/bbs/index.html
hello Alias!
2)修改配置文件
vim /usr/local/apache2/etc/httpd.conf
453 Include etc//extra/httpd-autoindex.conf
3)修改子配置文件
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>
4)重启服务 测试
sto
sta
测试 192.168.5.5/bbs/
实验2.虚拟主机
1)域名解析
C:\Windows\System32\drivers\etc\hosts
192.168.5.5 www.sina.com
192.168.5.5 www.sohu.com
2) 规划网站目录
mkdir -p /share/sina/
mkdir /share/sohu/
vim /share/sina/index.html
Sina!
vim /share/sohu/index.html
Sohu!
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
24 <Directory "/share/sina/">
25 Options Indexes
26 AllowOverride None
27 Require all granted
28 </Directory>
29
30 <Directory "/share/sohu/">
31 Options Indexes
32 AllowOverride None
33 Require all granted
34 </Directory>
35 <VirtualHost 192.168.5.5>
36 ServerAdmin [email protected]
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.5.5>
44 ServerAdmin [email protected]
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 (301永久重定向)
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
24 <Directory "/share/sina/">
25 Options Indexes FollowSymLinks
26 AllowOverride All
27 Require all granted
28 </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
1 <?php
2 echo "hello world!";
3 ?>
3)重启 测试
sto
sta
测试 www.sina.com/index7.html
云计算 云服务器 AWS 阿里云 腾讯云 百度云 华为云
阿里 云服务器 ECS
域名购买
服务器 购买 设置 登录
搭建LAMP架构
上线 windows->linux 1. 代码文件 上传到 linux服务器 2.数据库导入到linux服务器数据库上 3.配置文件 测试 (上线成功)