CentOS 7.2 配置Apache服务(httpd)--上篇
发布时间:2020-07-09 07:30:18 所属栏目:CentOS 来源:互联网
导读:一、Apache简介 Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器软件,可以在大多数电脑操作系统中运行,由于其跨平台和安全性(尽管不断有新的漏洞被发现,但由于其开放源代码的特点,漏洞总能被很快修补。因此总合来说,
一、Apache简介
二、安装Apache httpd
[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> 三、支持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/htmlnn";
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
四、支持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 ~]# vi /var/www/html/index.php
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php
print Date("Y/m/d");
?>
</div> </body>
</html>
[3] 创建phpinfo测试页,确认是都开启php支持 [root@linuxprobe ~]# echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php 五、支持Ruby
[1] 安装Ruby.
[root@linuxprobe ~]# yum -y install ruby
[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 .rb as CGI scripts
<Directory "/var/www/html/cgi-enabled">
Options +ExecCGI
AddHandler cgi-script .rb
</Directory>
[root@linuxprobe ~]# systemctl restart httpd
[4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。
[root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
[5] Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
[root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.rb
#!/usr/bin/ruby
print "Content-type: text/htmlnn"
print "<html>n<body>n"
print "<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">n"
print "Ruby Script Test Page"
print "n</div>n"
print "</body>n</html>n"
[root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.rb
六、支持Python
[1] 安装python.
[root@linuxprobe ~]# yum -y install python
[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 .py as CGI scripts
<Directory "/var/www/html/cgi-enabled">
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
[root@linuxprobe ~]# systemctl restart httpd
[4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。
[root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
[5] Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
[root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.py
#!/usr/bin/env python
print "Content-type: text/htmlnn"
print "<html>n<body>n"
print "<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">n"
print "Python Script Test Page"
print "n</div>n"
print "</body>n</html>n"
[root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.py
7、支持Userdir
[1] 配置 httpd.
[root@linuxprobe ~]# vi /etc/httpd/conf.d/userdir.conf
# line 17: comment out
#UserDir disabled
# line 24: uncomment
UserDir public_html
# line 31 - 35
<Directory "/home/*/public_html">
AllowOverride All
# change
Options None
# change
Require method GET POST OPTIONS
</Directory>
[root@linuxprobe ~]# systemctl restart httpd
[2] 创建一个测试页,使用普通用户通过客户端PC与Web浏览器和访问它,如果显示以下页面,就是正确的
[cent@linuxprobe ~]$ mkdir public_html
[cent@linuxprobe ~]$ chmod 711 /home/cent
[cent@linuxprobe ~]$ chmod 755 /home/cent/public_html
[cent@linuxprobe ~]$ vi ./public_html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
UserDir Test Page
</div>
</body>
</html>
(编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
