分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

linux学习-apache的安装和配置1

发布时间:2023-09-06 02:08责任编辑:胡小海关键词:apache配置
apache是最为常见和流行的web服务器,研究和使用很有必要。

一、安装和配置apache


安装apache

 yum install httpd httpd-tools

apche的相关配置文件


管理和控制apache

systemctl {start|stop|resart|reload} httpdsystemctl {enable|diable} httpd

apachectl控制apache

apachctl {start|stop|gracful|status} #启动、停止、重启、状态apchectl fullstatus #显示mod_status模块输出apachectl -V 或 httpd -V  #显示apache的编译参数apachectl -l 或 httpd -l  #查看编译模块apachectl -M 或 httpd -M    #列出所有模块apachectl -t 或 httpd -t    #检查配置文件的正确性apachectl -S 或 httpd -S    #主机虚拟机主机配置的正确性

apache配置文件

#/etc/httpd/conf/httpd.confServerRoot "/etc/httpd"                 #根目录设置Listen 80                        #监听本机所有80端口Include conf.modules.d/*.conf              #包含动态模块加载配置文件User apache                        #以apache用户执行服务进程/线程Group apache                       #以apche组执行服务进程/线程 ServerAdmin root@localhost                #Apache用户E-mail为rootlocalhost<Directory />                      #设置对ServerRoot目录的访问控制    AllowOverride none                #禁止使用基于目录的配置文件    Require all denied               #拒绝一切客户访问ServerRoot目录的访问控制</Directory>DocumentRoot "/var/www/html"              #主服务器的文档根目录为/var/www/html<Directory "/var/www">                 #设置对/var/www目录的访问控制    AllowOverride None               #禁止使用基于目录的配置文件    Require all granted                            #允许一切客户访问/var/www目录</Directory><Directory "/var/www/html">                             #设置对/var/www/html目录的访问控制    Options Indexes FollowSymLinks                 #允许为此目录生成文件列表,语序符号链接跟随    AllowOverride None                              #禁止使用基于目录的配置文件    Require all granted                            #允许一切客户访问/var/www/html目录</Directory><IfModule dir_module>    DirectoryIndex index.html                       #指定目录的主页文件为index.html</IfModule><Files ".ht*">    Require all denied                             #拒绝一切客户访问“.ht*”文件</Files>ErrorLog "logs/error_log"                               #指定错误文件日志的位置LogLevel warn                                           #指定记录高于warn级别的错误日志<IfModule log_config_module>    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined    LogFormat "%h %l %u %t \"%r\" %>s %b" common    <IfModule logio_module>          LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio    </IfModule>    CustomLog "logs/access_log" combined           #指定访问日志文件的位置和格式</IfModule><IfModule alias_module>    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"</IfModule><Directory "/var/www/cgi-bin">    AllowOverride None    Options None    Require all granted</Directory><IfModule mime_module>    TypesConfig /etc/mime.types    AddType application/x-compress .Z    AddType application/x-gzip .gz .tgz    AddType text/html .shtml    AddOutputFilter INCLUDES .shtml</IfModule>AddDefaultCharset UTF-8                                #指定默认字符集<IfModule mime_magic_module>    MIMEMagicFile conf/magic</IfModule>EnableSendfile on                                       #启用Sendfile机制以提高apche性能IncludeOptional conf.d/*.conf                           #包含conf.d/*.conf目录下的配置文件


二、apache的基本配置

访问控制

    apache可以根据访问者的IP地址或域名来决定是否提供资源。apache2.4版本中,访问控制功能由mod_authz_core和mode_authz_host模块,使用Require指令实现访问控制

Require all granted            #表示允许所有主机访问Require all denied             #表示拒绝所有主机访问Require lcoal                  #表示仅允许本地主机访问Reuire [not} host              #表示允许或禁止指定主机或域访问Require {not] ip               #表示允许或禁止指定ip地址访问

别名

    使用别名(ALIAS)机制可以将文档根目录(/var/www/html)以外的内容加入站点。配置别名可以使用Alias指令,使用Alias指令可以映射URL到文件系统。

格式1:Alias/URL-path/"/path/to/other/directory/"格式2:Alias/URL-path-filename "/path/to/other/directory/filename"

例1:配置文件/etc/httpd/conf.d/autoindex.conf中定义Alias

grep -w^Alias/etc/httpd/conf.d/autoindex.confAlias /icons/ "/usr/share/httpd/icons/"====================================将http://localhost/icons/的访问映射到文件系统的/usr/share/httpd/icons/的目

例2:配置文件/etc/httpd/conf,d/welcome.conf中定义Alias

grep -w ^Alias/etc/httpd/conf.d/welcome.conf|tail -1Alias /images/powerrdby.png /usr/share/httpd/noindex/images/powererdby.png====================================将http://localhost/images/powerdby.png的访问映射到文件/ usr/share/httpd/noindex/images/powerdby.png


linux学习-apache的安装和配置1

原文地址:http://blog.51cto.com/11555417/2154150

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved