linux-httpd服务配置

配置本地yum源

先挂镜像

1
2
3
4
[root@controller ~]# mount /dev/cdrom /mnt/  #挂载镜像
mount: /dev/sr0 写保护,将以只读方式挂载
[root@controller ~]# mkdir /opt/centos #创建一个文件夹
[root@controller ~]# cp /mnt/* /opt/centos/ #镜像内容复制到文件夹

再写yum.repo文件

1
2
3
4
5
6
7
[root@controller ~]# vim /etc/yum.repos.d/centos.repo

[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
1
2
3
[root@controller ~]# yum clean all && yum repolist
源标识 源名称 状态
centos centos 4,070

下载httpd服务

1
[root@server ~]# yum install httpd -y

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
##修改配置文件httpd.conf=中以下内容
[root@server ~]# vim /etc/httpd/conf/httpd.conf

Listen 82 #监听端口号 82 默认是80
DocumentRoot "/var/www/html/file"
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
IndexOptions Charset=UTF-8 ##添加这一行 避免中文乱码
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>

mkdir /var/www/html/file

设置目录允许访问

1
2
3
##设置前提你的selinux 是打开的
##如果你的selinux 是关闭的,那就不需要设置
[root@server ~]# resrestore -Rv /var/www/html/file

selinux/firewalld 开放端口

在这里,如果我们是自己使用或者是测试环境的情况,可以直接关闭firewalld 和 selinux

selinux 开放

1
2
3
4
##selinux 开放82端口
[root@server ~]# semanage port -a -t http_port_t -p tcp 82
[root@server ~]# semanage port --list | grep 82
http_port_t tcp 83, 82, 80, 81, 443, 488, 8008, 8009, 8443, 9000

firewalld 开放

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

##firewalld 开放82 端口
[root@server ~]# firewall-cmd --add-port=82/tcp
success
[root@server ~]# firewall-cmd --reload ## 验证
success
[root@server ~]# firewall-cmd --list-all ## 查看
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client ssh
ports: 82/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

selinux 小知识

1
2
3
4
5
6
[root@server ~]# setenforce 1   #临时修改selinux监控模式 严格
[root@server ~]# getenforce #查看当前模式
Enforcing #严格模式 不符合检查标本不允许通过
[root@server ~]# setenforce 0 #临时修改。。警告模式
[root@server ~]# getenforce
Permissive #警告模式 不符合检查标准也允许通过但是会警告

上传资料

图一

使用ftp工具上传内容到服务器
上传到/var/www/html/file

设置一下字符截断

1
2
vim /etc/httpd/conf.d/autoindex.conf
IndexOptions FancyIndexing HTMLTable VersionSort NameWidth=*

开启服务设置开机自启

1
2
3
[root@server ~]# systemctl start httpd  #开启服务
[root@server ~]# systemctl enable httpd #开机自启
[root@server ~]# systemctl status httpd #查看状态

测试

ip :port
图二