Installation and configuration of Linux learning-apache 1

Source: Internet
Author: User

Apache is the most common and popular Web server, which is necessary for research and use.

First, install and configure Apache


Installing Apache

Yum Install httpd Httpd-tools

Apche Related configuration Files


Manage and control Apache

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

Apachectl Control Apache

Apachctl {start|stop|gracful|status} #启动, stop, restart, status Apchectl fullstatus #显示mod_status模块输出apachectl-V or Httpd-v # Displays the compilation parameters of Apache Apachectl-l or httpd-l #查看编译模块apachectl-M or httpd-m #列出所有模块apachectl-T or httpd-t #检查配置文件的正确性apach Ectl-s or Httpd-s #主机虚拟机主机配置的正确性

Apache configuration file

#/etc/httpd/conf/httpd.confserverroot  "/ETC/HTTPD"                    #根目录设置Listen  80                         # Monitor all 80 ports on this machine include conf.modules.d/*.conf                #包含动态模块加载配置文件User  apache                          #以apache用户执行服务进程/Thread Group  apache                         #以apche组执行服务进程/Threads  ServerAdmin [email protected]                 # Apache User e-mail rootlocalhost<directory />                        #设置对ServerRoot目录的访问控制     AllowOverride none                  #禁止使用基于目录的配置文件      Require all denied                 #拒绝一切客户访问ServerRoot目录的访问控制 </Directory>DocumentRoot  "/var/www/html"                 #主服务器的文档根目录为/var/www/html< directory  "/var/www" >                   #设置对 access control for the/VAR/WWW directory     AllowOverride None                 #禁止使用基于目录的配置文件      Require all granted                              #允许一切客户访问/var/www Catalogue </Directory>< directory  "/var/www/html" >                               #设置对/var Access control for the/www/html directory     Options Indexes FollowSymLinks                   #允许为此目录生成文件列表, word order symbolic link follow      AllowOverride None                               # Prohibit use of directory-based configuration files     Require all granted                              #允许一切客户访问/var/ Www/html Catalogue </Directory><IfModule dir_module>    DirectoryIndex  index.html                         #指定目录的主页文件为index .html</ifmodule><files  ". ht*" >     Require all denied                                #拒绝一切客户访问 ". ht*" File </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           # Specify the location and format of the access log file </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 configuration files in the. d/*.conf Directory


Second, the basic configuration of Apache

Access control

Apache can decide whether to provide resources based on the visitor's IP address or domain name. In the apache2.4 version, access control functions are implemented by the Mod_authz_core and Mode_authz_host modules, using the Require directives for access control

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

Alias

Use the alias mechanism to join content other than the document root directory (/var/www/html) to the site. Configuration aliases can use the alias directive, which can be used to map URLs to file systems using the alias directive.

Format 1:alias/url-path/"/path/to/other/directory/" format 2:alias/url-path-filename "/path/to/other/directory/filename"

Example 1: alias is defined in configuration file/etc/httpd/conf.d/autoindex.conf

grep-w^alias/etc/httpd/conf.d/autoindex.confalias/icons/"/usr/share/httpd/icons/" ============================= ======= Maps http://localhost/icons/access to the/usr/share/httpd/icons/of the file system.

Example 2: alias is defined in configuration file/etc/httpd/conf,d/welcome.conf

Grep-w ^alias/etc/httpd/conf.d/welcome.conf|tail-1alias/images/powerrdby.png/usr/share/httpd/noindex/images/ powererdby.png==================================== mapping Http://localhost/images/powerdby.png access to files/usr/share/ Httpd/noindex/images/powerdby.png


Installation and configuration of Linux learning-apache 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.