标签:linux运维
Linux运维 第三阶段 (七) apache服务
一、协议: HTTP超文本传输协议;核心:HTML超文本标记语言
URL:统一资源定位符http://或https://
搭建环境:linux+apache+mysql+php
linux+nginx+mysql+php
windows+IIS+SQLserver+asp
rpm包安装所需软件:httpd,mysql,mysql-server,php,php-devel,php-mysql.
配置文件:/usr/local/apache2/etc/httpd.conf
/usr/local/apache2/etc/extra/*.conf
/etc/httpd/conf/httpd.conf (RPM包安装位置
默认网页保存位置:/usr/local/apache2/htdocs/
/var/www/html (RPM包
日志保存位置:/usr/local/apache2/logs/
/var/log/httpd/ (RPM包
二、1、常用配置项:
ServerRoot (apache主目录
Listen (监听端口
LocalModule (加载的相关模块
User
Group
ServerAdmin (管理员邮箱
ServerName (服务器名,没有域名解析时使用临时解析,默认不开启
ErrorLog "logs/error_log" (错误日志
CustomLog "logs/access_log" common (正确访问日志
DirectoryIndex index.html index.php (默认网页文件名,优先级顺序
Include etc/extra/httpd-vhosts.conf (子配置文件中的内容也会加载生效
2、目录及权限:
DocumentRoot "/usr/local/apache2/htdocs" (主页目录
<Directory "/usr/local/apache2/htdocs" >
None (没有任何额外权限
All (所有权限
Indexes (浏览权限,当此目录下没有默认网页文件时,显示目录内容
FollowSymLinks (准许软链接到其它目录
AllowOverride None (定义是否允许目录下.htaccess文件中的权限生效
None (.htaccess中权限不生效
All (.htaccess中所有权限都生效
AuthConfig (.htaccess中只有网页认证的权限生效
Require all granted (访问控制列表
</Directory>
3、目录别名
Alias /webpath /full/filesystem/path
三、例:1、用户身份验证:
#vi /usr/local/apache2/etc/httpd.conf
Allowoverride All
#vi /usr/local/apache2/htdocs/.htaccess
AuthName "50docs" (提示信息
AuthType basic (加密类型
AuthUserfile /usr/local/apache2/htdocs/apache.psd(密码文件,文件名自定义
require valid-user (允许密码文件中所有用户访问
#/usr/local/apache2/bin/htpasswd -c /usr/loca/apache2/htdocs/apache.psd zhangsan
(建立密码文件,只有添加第一个用户时才能用-c,从第二个用户开始添加更多用户用-m
#/usr/local/apache2/bin/htpasswd -m /usr/local/apache2/htdocs/apache.pas lisi
(添加更多用户使用-m
2、虚拟主机:
基于IP的虚拟主机:一台服务器,多个IP,搭建多个网站
基于端口的虚拟主机:一台服务器,一个IP,搭建多个网站,每个网站使用不同的端口访问
基于域名的虚拟主机:一台服务器,一个IP,搭建多个网站,每个网站使用不同域名访问
#vi /usr/local/apache2/etc/httpd.conf
打开 Include etc/ /extra/httpd-vhosts.conf (以下三个实验,均需打开此项
》例:基于IP的虚拟主机
#ifconfig eth0:1 192.168.216.227 netmask 255.255.255.0 (临时生效
#cp ifcfg-eth0 ifcfg-eth0:1 (永久生效需改配置文件
#vi /usr/local/apache2/etc/extra/httpd-vhost.conf
<VirtualHost 192.168.216.226>
DocumentRoot "/usr/local/apache2/htdocs/baidu"
ServerName www.baidu.com
ErrotLog "……-error_log"
CustomLog "……-access_log" common
<Directory "/usr/local/apache2/htdocs/baidu">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.216.227>
DocumentRoot "/usr/local/apache2/htdocs/xdl"
ServerName www.xdl.com
ErrorLog "……-error_log"
CustomLog "……-access_log" common
<Directory "/usr/local/apache2/htdocs/xdl"
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
#mkdir –v /usr/local/apache2/htdocs/{baidu,xdl}
#cd baidu
#echo "www.baidu.com" >> index.html
#cd xdl
#echo "www.xdl.com" >> index.html
#vi /usr/local/apache2/etc/httpd.conf
DocumentRoot "/usr/local/apache2//htdocs" (关掉默认网页设置
#/usr/local/apache2/bin/apachectl stop--->start
#elinks 192.168.216.226
#elinks 192.168.216.227
》例:基于端口的虚拟主机
#vi /usr/local/apache2/etc/extra/httpd-vhosts.conf (在上例的基础上修改如下内容
Listen 8080
<VirtualHost 192.168.216.226:80>
……
</VirtualHost>
<VirtualHost 192.168.216.226:8080>
……
</VirtualHost>
#elinks 192.168.216.226:80
#elinks 192.168.216.226:8080
》例:基于域名的虚拟主机
布好域名服务器
#vi /usr/local/apache2/etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
…… (同上例中内容
</VirtualHost>
#elinks www.baidu.com(www.xdl.com)
3、个人主页:
#vi /usr/lcoal/apache2/etc/httpd.conf
Include etc/extra/httpd-userdir.conf (打开子配置文件
LoadModule userdir module modules/mod_userdir.so (打开模块
#vi /usr/local/apache2/etc/extra/httpd-userdir.conf (此配置文件已设置好,不需改动
#useradd zhangsan
#useradd lisi
#mkdir /home/zhangsan/public_html
#mkdir /home/lisi/public_html
#echo "zhangsan‘s HomePage" >> /home/zhangsan/public_html/index.html
#echo "lisi‘s HomePage" >> /home/lisi/public_html/index.html
#chmod o+x /home/zhangsan
#chmod o+x /home/lisi
#elinks 192.168.216.226/~zhangsan
#elinks 192.168.216.226/~lisi
来自兄弟连培训
本文出自 “Linux运维重难点学习笔记” 博客,请务必保留此出处http://jowin.blog.51cto.com/10090021/1659486
标签:linux运维
原文地址:http://jowin.blog.51cto.com/10090021/1659486