Apache服务

1.apache

企业中常用的web服务,用来提供http://(超文本传输协议)

2.apache的安装部署

yum install httpd -y ##apache软件
yum install httpd-manual ##apache的手册
systemctl start httpd ##启动httpd服务
systemctl enable httpd ##设定开机自启动
firewall-cmd --list-all ##列出火墙信息
firewall-cmd --permanent --add-service=http ##永久允许http
firewall-cmd --reload ##火墙从新加载策略

[root@desktop51 ~]# yum install httpd
Loaded plugins: langpacks
rhel_dvd                                                 | 4.1 kB     00:00     
(1/2): rhel_dvd/group_gz                                   | 134 kB   00:00     
(2/2): rhel_dvd/primary_db                                 | 3.4 MB   00:00     
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch           Version              Repository        Size
================================================================================
Installing:
 httpd               x86_64         2.4.6-17.el7         rhel_dvd         1.2 M
Installing for dependencies:
 apr                 x86_64         1.4.8-3.el7          rhel_dvd         103 k
 apr-util            x86_64         1.5.2-6.el7          rhel_dvd          92 k
 httpd-tools         x86_64         2.4.6-17.el7         rhel_dvd          77 k
 mailcap             noarch         2.1.41-2.el7         rhel_dvd          31 k

Transaction Summary
================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 1.5 M
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------
Total                                               72 MB/s | 1.5 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7.x86_64                                       1/5 
  Installing : apr-util-1.5.2-6.el7.x86_64                                  2/5 
  Installing : httpd-tools-2.4.6-17.el7.x86_64                              3/5 
  Installing : mailcap-2.1.41-2.el7.noarch                                  4/5 
  Installing : httpd-2.4.6-17.el7.x86_64                                    5/5 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                  1/5 
  Verifying  : httpd-tools-2.4.6-17.el7.x86_64                              2/5 
  Verifying  : apr-1.4.8-3.el7.x86_64                                       3/5 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  4/5 
  Verifying  : httpd-2.4.6-17.el7.x86_64                                    5/5 

Installed:
  httpd.x86_64 0:2.4.6-17.el7                                                   

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                 apr-util.x86_64 0:1.5.2-6.el7       
  httpd-tools.x86_64 0:2.4.6-17.el7        mailcap.noarch 0:2.1.41-2.el7       

Complete!
[root@desktop51 ~]# yum install httpd-manual.noarch 
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package httpd-manual.noarch 0:2.4.6-17.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch          Version                Repository       Size
================================================================================
Installing:
 httpd-manual        noarch        2.4.6-17.el7           rhel_dvd        1.3 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.3 M
Installed size: 5.5 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-manual-2.4.6-17.el7.noarch                             1/1 
  Verifying  : httpd-manual-2.4.6-17.el7.noarch                             1/1 

Installed:
  httpd-manual.noarch 0:2.4.6-17.el7                                            

Complete!
[root@desktop51 ~]# systemctl start httpd
[root@desktop51 ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@desktop51 ~]# firewall-cmd  --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

[root@desktop51 ~]# firewall-cmd --permanent  --add-service=http
success
[root@desktop51 ~]# firewall-cmd  --reload 
success
[root@desktop51 ~]# firewall-cmd  --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client http ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

/var/www/html ##apache的/目录,默认发布目录
/var/www/html/index ##apache的默认发布文件
vim /var/www/html/index
写入:

hello world


测试:
这里写图片描述

3.apache的基础信息

主配置目录: /etc/httpd/conf
主配置文件: /etc/httpd/conf/httpd.conf
子配置目录: /etc/httpd/conf.d/
子配置文件: /etc/httpd/conf.d/*.conf
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口: 80
默认安全上下文:httpd_sys_content_t
程序开启默认用户: apache
apache日志: /etc/httpd/logs/*

修改默认端口:
vim /etc/httpd/conf/httpd.conf
43 Listen 8080 ##修改默认端口为8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

[root@desktop51 ~]# vim /etc/httpd/conf/httpd.conf
-----------------------
 # Change this to Listen on specific IP addresses as shown below to 
 38 # prevent Apache from glomming onto all bound IP addresses.
 39 #
 40 #Listen 12.34.56.78:80
 41 Listen 80
 42 
 43 #
 44 # Dynamic Shared Object (DSO) Support
 45 #
 46 # To be able to use the functionality of a module which was built as a DSO
you
 -------------------
[root@desktop51 ~]# firewall-cmd --permanent --add-port=8080/tcp
success
[root@desktop51 ~]# firewall-cmd --reload 
success
[root@desktop51 ~]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client http ssh
  ports: 8080/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

修改默认发布文件:
默认发布文件就是访问apache时没有指定文件名称时默认访问的文件
这个文件可以指定多个,有访问顺序
vim /etc/httpd/conf/httpd.conf

[root@desktop51 ~]# vim /etc/httpd/conf/httpd.conf 
162 <IfModule dir_module>
163     DirectoryIndex index.html  test.html
164 </IfModule>

修改默认发布目录:
vim /etc/httpd/conf/httpd.conf

[root@desktop51 ~]# vim /etc/httpd/conf/httpd.conf
118 DocumentRoot "/var/www/html"
119 <Directory"/www">
120         Require all granted
121 </Directory>

在selinux强制情况下需要修改安全上下文标签

[root@desktop51 ~]# semanage fcontext  -a -t httpd_sys_content_t '/www(/.*)?\'
[root@desktop51 ~]# restorecon -RvvF /www/

猜你喜欢

转载自blog.csdn.net/lx543733371/article/details/80270576