首页 > 代码库 > apache

apache

######apache的安装####

yum install httpd -y

systemctl start httpd

systemctl enable httpd

systemctl stop firewalld

systemctl disable firewalld

 

 

#####apache信息####

1)apache的默认发布文件

index.html

2)apache的配置文件

/etc/httpd/conf/httpd.conf

/etc/httpd/conf.d/*.conf

3)apache的默认发布目录

/var/www/html

4)apache的默认端口

80

 

####apache的基本配置####

1.修改默认发布文件

[root@localhost mysqladmin]# vim /etc/httpd/conf/httpd.conf

164     DirectoryIndex  westos.html index.html   ##增加westos.html(哪个写在前面哪个优先)

[root@localhost ~]# cd /var/www/html/

[root@localhost html]# ls

index.html  mysqladmin

[root@localhost html]# vim westos.html

 

2.修改默认发布目录

[root@localhost ~]# getenforce

Permissive

 ##当selinux是disabled或者Permissive的状态

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

 

DocumentRoot "/westos/www/test"

<Directory "/westos/www/test">

    Require all granted

</Directory>

[root@localhost ~]# systemctl restart httpd

[root@localhost ~]# mkdir -p /westos/www/test/  ##建立目录

[root@localhost ~]# vim /westos/www/test/westos.html   ##任意想表达的东西

[root@localhost ~]# systemctl restart httpd

  

  ##当selinux是enforcing状态

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

DocumentRoot "/westos/www/test"

<Directory "/westos/www/test">

    Require all granted

</Directory>

[root@localhost ~]# systemctl restart httpd

 

semanage fcontext -a -t httpd_sys_content_t ‘/westos(/.*)?‘  ##更改安全上下文

restorecon -RvvF /westos  ##刷新

[root@localhost html]# semanage fcontext -a -t httpd_sys_content_t ‘/westos(/.*)?‘

[root@localhost html]# restorecon -RvvF /westos

restorecon reset /westos context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0

restorecon reset /westos/www context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0

restorecon reset /westos/www/test context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0

restorecon reset /westos/www/test/westos.html context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0

 

 

3.apache的访问控制

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin">

     Order Allow,Deny     ##Order哪个写在前面表示先读哪个

     Allow from All        ##允许所有人访问admin目录但是拒绝13主机

     Deny from 172.25.254.13

</Directory>

###设定用户的访问###

[root@localhost ~]# htpasswd -cm /etc/httpd/accessuser admin  ##创建用户(-c指创建,-m指名称)

New password:

Re-type new password:

Adding password for user admin

[root@localhost ~]# htpasswd -m /etc/httpd/accessuser tom   ##再次创建不用-c,否则会覆盖之前建立的用户

New password:

Re-type new password:

htpasswd: password verification error

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

 

<Directory "/var/www/html/admin">

    AuthUserFile /etc/httpd/accessuser      ##用户认证文件

    AuthName "Please input your name and password !!"   ##用户认证提示信息

    AuthType basic     ##认证类型

    Require valid-user    ##认证用户,认证文件中所有用户都可以通过

   # [Require User Admin ]   ##只允许认证文件中admin用户访问,二选一

</Directory>

[root@localhost ~]# systemctl restart httpd

[root@localhost html]# mkdir /var/www/html/admin

[root@localhost ~]# cd /var/www/html/admin/

[root@localhost admin]# touch file

[root@localhost admin]# ls

file

 

检测:

172.25.254.112/admin

 

 

4.apache语言支持

php html cgi

 

html语言默认支持

 

 

php语言

vim index.php

<?php

 phpinfo();

?>

yum install php -y

systemctl restart httpd

 

 

cgi语言

mkdir /var/www/html/cgi

vim index.cgi

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print `data`;    ##` `指优先执行此项

 

 

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/cgi">

Options +ExecCGI

AddHandler cgi-script .cgi

</Directory>





本文出自 “AELY木” 博客,请务必保留此出处http://12768057.blog.51cto.com/12758057/1926246

apache