Linux装多个apache,linux学习-apache的安装和配置1

apache是最为常见和流行的web服务器,研究和使用很有必要。

一、安装和配置apache

安装apacheyum install httpd httpd-tools

apche的相关配置文件

21e614806a8aa4f5c8f3001289b83dc2.png

管理和控制apachesystemctl {start|stop|resart|reload} httpd

systemctl {enable|diable} httpd

apachectl控制apacheapachctl {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.conf

ServerRoot "/etc/httpd"                 #根目录设置

Listen 80                        #监听本机所有80端口

Include conf.modules.d/*.conf              #包含动态模块加载配置文件

User apache                        #以apache用户执行服务进程/线程

Group apache                       #以apche组执行服务进程/线程

ServerAdmin root@localhost                #Apache用户E-mail为rootlocalhost

                      #设置对ServerRoot目录的访问控制

AllowOverride none                #禁止使用基于目录的配置文件

Require all denied               #拒绝一切客户访问ServerRoot目录的访问控制

DocumentRoot "/var/www/html"              #主服务器的文档根目录为/var/www/html

                 #设置对/var/www目录的访问控制

AllowOverride None               #禁止使用基于目录的配置文件

Require all granted                            #允许一切客户访问/var/www目录

                             #设置对/var/www/html目录的访问控制

Options Indexes FollowSymLinks                 #允许为此目录生成文件列表,语序符号链接跟随

AllowOverride None                              #禁止使用基于目录的配置文件

Require all granted                            #允许一切客户访问/var/www/html目录

DirectoryIndex index.html                       #指定目录的主页文件为index.html

Require all denied                             #拒绝一切客户访问“.ht*”文件

ErrorLog "logs/error_log"                               #指定错误文件日志的位置

LogLevel warn                                           #指定记录高于warn级别的错误日志

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %b" common

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

CustomLog "logs/access_log" combined           #指定访问日志文件的位置和格式

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

AllowOverride None

Options None

Require all granted

TypesConfig /etc/mime.types

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

AddType text/html .shtml

AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8                                #指定默认字符集

MIMEMagicFile conf/magic

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中定义Aliasgrep -w^Alias/etc/httpd/conf.d/autoindex.conf

Alias /icons/ "/usr/share/httpd/icons/"

====================================

将http://localhost/icons/的访问映射到文件系统的/usr/share/httpd/icons/的目

例2:配置文件/etc/httpd/conf,d/welcome.conf中定义Aliasgrep -w ^Alias/etc/httpd/conf.d/welcome.conf|tail -1

Alias /images/powerrdby.png /usr/share/httpd/noindex/images/powererdby.png

====================================

将http://localhost/images/powerdby.png的访问映射到文件/ usr/share/httpd/noindex/images/powerdby.png

options指令

option指令控制了在特定目录中将使用哪些服务器特性。通常出现在,容器中或.htaccess配置文件中。

以下为options指令常用的选项。

选项                                        说明

ALL                                        除了multiViews之外的所有特性,是默认设置

None                                     将不启用如何额外特性

ExceCGI                                 运行使用mod_cgi执行CGI脚本

FollowSymlinks                     服务器允许在此目录中使用符号链接

SymLinksIfOwnerMatch        服务器仅在符号链接于其目的目录或者文件的拥有者具有相同的uid时使用

Indexes                                 若一个映射到目录的URL被请求,而此目录又没有DirectoryIndex指定的文件(例如 Index.html),则服务器会返回mod_autoindex模块生成的一个格式化后目录列表

MultiViews                            允许使用mod_negotiaons提供协商的“多重视图”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值