Apache服务器配置

本文详细介绍了如何在CentOS上配置Apache服务器,包括安装Apache、配置服务器信息、启用Perl、PHP、Ruby和Python支持、配置Userdir、设置虚拟主机、创建SSL证书以及启用基本身份验证和WebDAV。通过这些步骤,你可以创建一个功能齐全的Web服务器。
摘要由CSDN通过智能技术生成

CentOS 配置Apache服务(httpd

一、Apache简介

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器软件,可以在大多数电脑操作系统中运行,由于其跨平台和安全性(尽管不断有新的漏洞被发现,但由于其开放源代码的特点,漏洞总能被很快修补。因此总合来说,其安全性还是相当高的。)。被广泛使用,是最流行的Web服务器软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。

软件图标

https://i-blog.csdnimg.cn/blog_migrate/4155687cd85e1ee7e4564520a35ef15d.png

二、安装Apache httpd

安装httpd以配置Web服务器, HTTP使用80 / TCP

[1] 安装 httpd.

[root@linuxprobe ~]# yum -y install httpd

# 删除默认欢迎页面

[root@linuxprobe ~]# rm -f /etc/httpd/conf.d/welcome.conf

[2] 配置httpd,将服务器名称替换为您自己的环境

[root@linuxprobe ~]# vi /etc/httpd/conf/httpd.conf

# line 86: 改变管理员的邮箱地址

ServerAdmin root@linuxprobe.org

# line 95: 改变域名信息

ServerName www.linuxprobe.org:80

# line 151: none变成All

AllowOverride All

# line 164: 添加只能使用目录名称访问的文件名

DirectoryIndex index.html index.cgi index.php

# add follows to the end

# server's response header(安全性)

ServerTokens Prod

# keepalive is ON

KeepAlive On

[root@linuxprobe ~]# systemctl start httpd

[root@linuxprobe ~]# systemctl enable httpd

[3] 如果Firewalld正在运行,请允许HTTP服务。,HTTP使用80 / TCP

[root@linuxprobe ~]# firewall-cmd --add-service=http --permanent

success

[root@linuxprobe ~]# firewall-cmd --reload

success

[4] 创建一个HTML测试页,并使用Web浏览器从客户端PC访问它。如果显示以下页面,是正确的

[root@linuxprobe ~]# vi /var/www/html/index.html

<html>

<body>

<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">

Welcome access LinuxProbe.org,This is Test Page!

</div>

</body>

</html>

https://i-blog.csdnimg.cn/blog_migrate/50f884078e12a49589df467b65f8efb1.png

三、支持Perl

启用CGI执行并使用Perl脚本

[1] 安装Perl.

[root@linuxprobe ~]# yum -y install perl perl-CGI

[2] 默认情况下,在“/var/www/cgi-bin”目录下允许CGI。 

可以使用Perl Scripts放在目录下。然而,它下面的所有文件都被处理为CGI。

# 下面的设置是CGI的设置

[root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf

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

[3] 如果你想允许在其他目录中的CGI,配置如下。 

例如,在“/var/www/html/cgi-enabled”中允许。

[root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf

# create new

# processes .cgi and .pl as CGI scripts

<Directory "/var/www/html/cgi-enabled">

    Options +ExecCGI

    AddHandler cgi-script .cgi .pl

</Directory>

[root@linuxprobe ~]# systemctl restart httpd

[4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。

[root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/linuxprobe/html/cgi-enabled

[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled

[5] 创建一个CGI测试页面,并使用Web浏览器从客户端PC访问它。如果显示以下页面,说明配置正确。

[root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.cgi

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "<html>\n<body>\n";

print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n";

print "CGI Test Page";

print "\n</div>\n";

print "</body>\n</html>\n";

[root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.cgi

https://i-blog.csdnimg.cn/blog_migrate/fdcf4733a49c76067877949b8fee0e7a.png

四、支持PHP

配置httpd以使用PHP脚本

[1] 安装PHP.

[root@linuxprobe ~]# yum -y install php php-mbstring php-pear

[root@linuxprobe ~]# vi /etc/php.ini

# line 878: 取消注释,设置时区

date.timezone = "Asia/Shanghai"

[root@linuxprobe ~]# systemctl restart httpd

[2] 创建一个PHP测试页面,并使用Web浏览器从客户端PC访问它。如果显示以下页面,它是确定。

[root@linuxprobe ~]# v

  • 10
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值