首页 > 代码库 > apache
apache
############apache的安装###############
vim /etc/yum.repos.d/rhel_dvd.repo
yum install -y httpd
systemctl start httpd
systemctl stop firewalld
systemctl enable httpd
systemctl disable firewalld
#############apache的信息###################
1.Apache主配置文件:
/etc/httpd/conf/httpd.conf
2.监听端口:80
3.apache的默认发布文件
index.html
4.apache的默认发布目录
/var/www/html
#############apache的基本设置####################
[root@localhost ~]# cd /var/www/html
[root@localhost html]# ls
[root@localhost html]# vim /var/www/html/westos.html
1 <h1>westos‘s page</h1>
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
166 <IfModule dir_module>
167 DirectoryIndex westos.html index.html
168 </IfModule>
[root@localhost html]# cd
[root@localhost ~]# mkdir /westos/www/html
[root@localhost ~]# mkdir /westos/www/test -p
1 /westos/www/test/westos.html‘s page
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
119 #DocumentRoot "/var/www/html"
120 DocumentRoot "/westos/www/test"
121 <Directory "/westos/www/test">
122 Require all granted
123 </Directory>
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# systemctl restart httpd
测试
############apache用户访问设置##########
[root@localhost html]# mkdir admin
[root@localhost admin]# vim admin
1 <h1>admin‘s page</h1>
[root@localhost html]# ls
admin index.html westos.html
[root@localhost html]# cd admin/
[root@localhost admin]# ls
[root@localhost admin]# vim admin
[root@localhost admin]# vim /etc/httpd/conf/httpd.conf
119 DocumentRoot "/var/www/html"
120 #DocumentRoot "/westos/www/test"
121 <Directory "/westos/www/test">
122 Require all granted
123 </Directory>
124 <Directory "/var/www/html/admin"> #####只允许75主机进行访问
125 Order Deny,Allow
126 Allow from 172.25.254.75
127 Deny from All
128 </Directory>
171 <IfModule dir_module>
172 DirectoryIndex admin westos.html index.html
173 </IfModule>
[root@localhost admin]# systemctl restart httpd
测试
[root@localhost admin]# vim /etc/httpd/conf/httpd.conf
119 DocumentRoot "/var/www/html"
120 #DocumentRoot "/westos/www/test"
121 <Directory "/westos/www/test">
122 Require all granted
123 </Directory>
124 <Directory "/var/www/html/admin"> ####允许其他用户访问,但不允许75主机访问
125 Order Allow,Deny
126 Allow from All
127 Deny from 172.25.254.75
128 </Directory>
[root@localhost admin]# systemctl restart httpd
测试
[root@localhost admin]# cd /etc/httpd
[root@localhost httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@localhost httpd]# htpasswd -cm /etc/httpd/accessuser admin
New password:
Re-type new password:
Adding password for user admin
[root@localhost httpd]# cat /etc/httpd/accessuser
admin:$apr1$hLx1MnNl$J9vtdAFtpX2BjL6eMD22x.
[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf
119 DocumentRoot "/var/www/html" #####允许有密码的用户访问
120 #DocumentRoot "/westos/www/test"
121 <Directory "/westos/www/test">
122 Require all granted
123 </Directory>
124 <Directory "/var/www/html/admin">
125 AuthUserFile /etc/httpd/accessuser ###用户认证文件
126 AuthName "please input your name and password !!" ###用户认证提示信息
127 AuthType basic ###认证类型
128 Require valid-user ###认证用户,认证文件中所用的用户可以通过
129 </Directory>
[root@localhost httpd]# systemctl restart httpd
测试
###############CGI#####################
[root@localhost html]# yum install -y php
[root@localhost html]# systemctl restart httpd
[root@localhost html]# vim index.php
1 <?php
2 phpinfo();
3 ?>
[root@localhost html]# cd /etc/httpd/conf.d
[root@localhost conf.d]# ls
autoindex.conf php.conf README userdir.conf welcome.conf
[root@localhost conf.d]# mkdir /var/www/html/cgi
[root@localhost conf.d]# cd /var/www/html/cgi
[root@localhost cgi]# ls
[root@localhost cgi]# vim index.cgi
1 #!/usr/bin/perl
2 print "Content-type: text/html\n\n";
3 print `date`;
[root@localhost cgi]# perl index.cgi
Content-type: text/html
2017年 5月 16日 火曜日 07:24:23 EDT
[root@localhost cg i]# chmod +x index.cgi
[root@localhost cgi]# vim /etc/httpd/conf/httpd.conf
130 <Directory "/var/www/html/cgi">
131 Options +ExecCGI
132 AddHandler cgi-script .cgi
133 </Directory>
176 <IfModule dir_module>
177 DirectoryIndex index.cgi admin westos.html index.html
178 </IfModule>
[root@localhost cgi]# systemctl restart httpd
测试
############apache虚拟主机##############
1.定义
可以让我们的一台apache服务器访问不同域名时显示不同的网页
2.建立测试页
mkdir virtual/news.westos.com -p
mkdir virtual/money.westos.com -p
mkdir virtual/news.westos.com/html -p
mkdir virtual/money.westos.com/html -p
echo "new.westos.com‘s page" >virtual/news.westos.com/html/index.html
echo "money.westos.com‘s page" >virtual/money.westos.com/html/index.html
3.配置
vim /etc/httpd/conf.d/default.conf ##指定域名的访问都访问default
1 <Virtualhost _default_:80> ##虚拟主机开启的端口
2 DocumentRoot "/var/www/html" ##虚拟主机的默认发布目录
3 CustomLog "logs/default.log" combined ##虚拟主机的日志
4 </Virtualhost>
vim /etc/httpd/conf.d/news.conf ##指定域名news.westos.com访问到默认发布目录
1 <Virtualhost *:80>
2 ServerName "news.westos.com"
3 DocumentRoot "/var/www/virtual/news.westos.com/html"
4 CustomLog "logs/news.log" combined
5 </Virtualhost>
6 <Directory "/var/www/virtual/news.westos.com/html"> ##默认发布目录的访问授权
7 Require all granted
8 </Directory>
vim /etc/httpd/conf.d/money.conf ####指定域名money.westos.com访问到默认发布目录
1 <Virtualhost *:80>
2 ServerName "money.westos.com"
3 DocumentRoot "/var/www/virtual/money.westos.com/html"
4 CustomLog "logs/news.log" combined
5 </Virtualhost>
6 <Directory "/var/www/virtual/money.westos.com/html"> ####默认发布目录的访问授权
7 Require all granted
8 </Directory>
3.在客户主机中添加解析
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.250 content.example.com
172.25.254.195 www.westos.com news.westos.com money.westos.com
~
测试
###############https###############
yum install -y mod_ssl
yum install -y crypto-utils
systemctl stop firewalld
genkey www.westos.com
apache