http://www.jb51.net/article/97434.htm

二、安装Apache httpd

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

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
35
[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

启用CGI执行并使用Perl脚本

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
[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

配置httpd以使用PHP脚本
[1] 安装PHP.

1
2
3
4
5
[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访问它。如果显示以下页面,它是确定。

1
2
3
4
5
6
7
8
9
10
[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

九、创建SSL证书

创建自己的SSL证书。但是,如果您使用您的服务器作为业务,最好购买和使用来自Verisigh的正式证书等。

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
35
36
37
38
39
40
41
42
[root@linuxprobe ~]# cd /etc/pki/tls/cert
cert.pem certs/ 
[root@linuxprobe ~]# cd /etc/pki/tls/certs/
[root@linuxprobe certs]# make server.key
umask 77 ; \
/usr/bin/openssl genrsa -aes128 2048 > server.key
Generating RSA private key, 2048 bit long modulus
...............................................................+++
....................................................................................................+++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
[root@linuxprobe certs]# openssl rsa -in server.key -out server.key
Enter pass phrase for server.key:
writing RSA key
[root@linuxprobe certs]# make server.csr
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN  #国家后缀
State or Province Name (full name) []:Shanghai #省
Locality Name (eg, city) [Default City]:Shanghai #市
Organization Name (eg, company) [Default Company Ltd]:LinuxProbe #公司
Organizational Unit Name (eg, section) []:DevOps #部门
Common Name (eg, your name or your server's hostname) []:linuxprobe.org #主机名
Email Address []:root@linuxprobe.org #邮箱
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:  #默认
An optional company name []:  #默认
#
[root@linuxprobe certs]# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
Signature ok
subject=/C=CN/ST=Shanghai/L=Shanghai/O=LinuxProbe/OU=DevOps/CN=linuxprobe.org/emailAddress=root@linuxprobe.org
Getting Private key

十、配置SSL

[1] 配置SSL.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@linuxprobe ~]# yum -y install mod_ssl
[root@linuxprobe ~]# vi /etc/httpd/conf.d/ssl.conf
# line 59: 取消注释
DocumentRoot "/var/www/html"
# line 60: 取消注释,定义域名
ServerName linuxprobe.org:443
# line 75: 改变SSLProtocol
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2
 
# line 100: 改成刚刚创建的server.crt
SSLCertificateFile /etc/pki/tls/certs/server.crt
# line 107: 改成刚刚创建的server.key
SSLCertificateKeyFile /etc/pki/tls/certs/server.key
[root@www ~]# systemctl restart httpd

[2] 如果Firewalld正在运行,请允许HTTPS服务。 HTTPS使用443 / TCP

1
2
3
4
[root@www ~]# firewall-cmd --add-service=https --permanent
success
[root@www ~]# firewall-cmd --reload
 
success

十一、启用基本身份验证

启用基本身份验证以限制特定网页的访问

[1]例如,在目录[/var/www/html/auth-basic]下设置基本身份验证设置。

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
[root@linuxprobe ~]# vi /etc/httpd/conf.d/auth_basic.conf
# 创建新配置文件
<Directory /var/www/html/auth-basic>
  AuthType Basic
  AuthName "Basic Authentication"
  AuthUserFile /etc/httpd/conf/.htpasswd
  require valid-user
</Directory>
# 添加用户:使用“-c”创建新文件(仅为初始注册添加“-c”选项)
[root@linuxprobe ~]# htpasswd -c /etc/httpd/conf/.htpasswd wang
 
New password: # set password
 
Re-type new password: # confirm
 
Adding password for user wang
[root@linuxprobe ~]# systemctl restart httpd
[root@linuxprobe ~]# mkdir /var/www/html/auth-basic
 
[root@linuxprobe ~]# vi /var/www/html/auth-basic/index.html
# create a test page
 
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: wanger;">
Test Page for Basic Auth
</div>
</body>
</html>

CentOS 7.2配置Apache服务httpd(上)的更多相关文章

  1. CentOS 7.2配置Apache服务httpd小伙伴们可以参考一下

    这篇文章主要为大家详细介绍了CentOS 7.2配置Apache服务 httpd上篇,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 一.Perl + mod_perl 安装mod_perl使Per ...

  2. CentOS 6.5配置nfs服务

    CentOS 6.5配置nfs服务 网络文件系统(Network File System,NFS),一种使用于分散式文件系统的协议,由升阳公司开发,于1984年向外公布.功能是通过网络让不同的机器.不 ...

  3. CentOS 7安装配置Apache HTTP Server

    原文 CentOS 7安装配置Apache HTTP Server   RPM安装httpd # yum -yinstall httpd //安装httpd会自动安装一下依赖包: apr apr-ut ...

  4. 阿里云服务器下安装LAMP环境(CentOS Linux 6.3) 安装与配置 Apache 服务

    想让我们的阿里云服务器成为一台 Web 服务器,我们需要安装一个 Web 服务器软件,比如 Apache ,或者 Nginx 等等.下面我们就一起来安装一个 Apache 服务. 我们可以使用 yum ...

  5. Mac下配置Apache服务

    这篇文章主要是针对Mac用户,第一次搭建本地开发环境的同学,已经搭建过的同学可以忽略. Mac自带的Apache还是XAMPP? That is a question. 其实自带的apache也够用了 ...

  6. CentOS 安装以及配置Apache php mysql

    准备篇: 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dp ...

  7. Centos 下,配置 Apache + Python + Django + postgresSQL 开发环境

    用 Python 搭建一个 Web 服务器 文章结构 一.安装  Apache.Python.django 二.安装 mod_wsgi,Apache 为 Python 提供的 wsgi 模块  三.将 ...

  8. 超详细 值得收藏 linux CentOS 7 配置Apache服务【转发+新增】

    一.Apache简介 Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器软件,可以在大多数电脑操作系统中运行,由于其跨平台和安全性(尽管不断有 ...

  9. CentOS安装和配置Apache(httpd)

    1. 安装httpd yum install httpd #安装apache 2. 启动httpd systemctl start httpd.service #启动apache 3. 随服务器自启动 ...

随机推荐

  1. Macbook Pro上安装Windows 7虚机

    折腾了大半天,终于搞定. 首先是安装VirtualBox,之后关键的是需要Win7虚机种子,百度了下去系统之家下的. 如果不是Ghost系统的话,VirtualBox可以直接load安装. 但是那边都 ...

  2. laravel 环境自编译过程

    [原创] 看到此文的朋友看完后也许会失望,但我尽最大努力不让搜友们失望,以下是自己操作的笔记用以整理提高 虽然 laravel 官方已给出了安装 laravel 框架所需的环境盒子 使用Vagrant ...

  3. Log4j配置详解之log4j.xml

    Log4j配置详解之log4j.xml Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息. ...

  4. Wdatepicker日期控件的使用指南

    示例2-3-1 起始日期简单应用 示例2-3-2 alwaysUseStartDate属性应用 示例2-3-3 使用内置参数 示例 2-4-1: 年月日时分秒 示例 2-4-2 时分秒 示例 2-4- ...

  5. zookeeper基本讲解(Java版,真心不错)

    1. 概述 Zookeeper是Hadoop的一个子项目,它是分布式系统中的协调系统,可提供的服务主要有:配置服务.名字服务.分布式同步.组服务等. 它有如下的一些特点: 简单 Zookeeper的核 ...

  6. 第十一章 Helm-kubernetes的包管理器(上)

    Helm - K8s的包管理器 11.1 Why Helm K8s能够很好的组织和编排容器,但它缺少一个更高层次的应用打包工具,Helm就是干这个的. 比如对于一个MySQL服务,K8s需要部署如下对 ...

  7. python学习(二十三) String(下) 分片和索引

    分片: 记住, 是开闭区间. a = "abcdef"print(a[:])print(a[1:])print(a[:3])print(a[-2])print(a[:-2])pri ...

  8. Oracle重建临时表空间

    [oracle@hd58 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Wed Jun 27 11:58:25  ...

  9. Julia - 函数返回值

    return 返回值 要返回函数最后一个表达式的值,可以省略 return julia> function f(x, y) x + y end f (generic function with ...

  10. jquery制作滚动条到一定位置触发

    $(function(){ var nav=$(".nav"); //得到导航对象 var win=$(window); //得到窗口对象 var sc=$(document);/ ...