CentOS 7.2配置Apache服务httpd(上)
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变成AllAllowOverride All# line 164: 添加只能使用目录名称访问的文件名DirectoryIndex index.html index.cgi index.php# add follows to the end# server's response header(安全性)ServerTokens Prod# keepalive is ONKeepAlive On[root@linuxprobe ~]# systemctl start httpd[root@linuxprobe ~]# systemctl enable httpd[3] 如果Firewalld正在运行,请允许HTTP服务。,HTTP使用80 / TCP[root@linuxprobe ~]# firewall-cmd --add-service=http --permanentsuccess[root@linuxprobe ~]# firewall-cmd --reloadsuccess[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.conf247: 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/perlprint "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/certcert.pem certs/ [root@linuxprobe ~]# cd /etc/pki/tls/certs/[root@linuxprobe certs]# make server.keyumask 77 ; \/usr/bin/openssl genrsa -aes128 2048 > server.keyGenerating 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.keyEnter pass phrase for server.key:writing RSA key[root@linuxprobe certs]# make server.csrumask 77 ; \/usr/bin/openssl req -utf8 -new -key server.key -out server.csrYou are about to be asked to enter information that will be incorporatedinto 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 blankFor 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' attributesto be sent with your certificate requestA challenge password []: #默认An optional company name []: #默认#[root@linuxprobe certs]# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650Signature oksubject=/C=CN/ST=Shanghai/L=Shanghai/O=LinuxProbe/OU=DevOps/CN=linuxprobe.org/emailAddress=root@linuxprobe.orgGetting 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: 改变SSLProtocolSSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2# line 100: 改成刚刚创建的server.crtSSLCertificateFile /etc/pki/tls/certs/server.crt# line 107: 改成刚刚创建的server.keySSLCertificateKeyFile /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 --permanentsuccess[root@www ~]# firewall-cmd --reloadsuccess |
十一、启用基本身份验证
启用基本身份验证以限制特定网页的访问
[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 wangNew password: # set passwordRe-type new password: # confirmAdding 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(上)的更多相关文章
- CentOS 7.2配置Apache服务httpd小伙伴们可以参考一下
这篇文章主要为大家详细介绍了CentOS 7.2配置Apache服务 httpd上篇,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 一.Perl + mod_perl 安装mod_perl使Per ...
- CentOS 6.5配置nfs服务
CentOS 6.5配置nfs服务 网络文件系统(Network File System,NFS),一种使用于分散式文件系统的协议,由升阳公司开发,于1984年向外公布.功能是通过网络让不同的机器.不 ...
- CentOS 7安装配置Apache HTTP Server
原文 CentOS 7安装配置Apache HTTP Server RPM安装httpd # yum -yinstall httpd //安装httpd会自动安装一下依赖包: apr apr-ut ...
- 阿里云服务器下安装LAMP环境(CentOS Linux 6.3) 安装与配置 Apache 服务
想让我们的阿里云服务器成为一台 Web 服务器,我们需要安装一个 Web 服务器软件,比如 Apache ,或者 Nginx 等等.下面我们就一起来安装一个 Apache 服务. 我们可以使用 yum ...
- Mac下配置Apache服务
这篇文章主要是针对Mac用户,第一次搭建本地开发环境的同学,已经搭建过的同学可以忽略. Mac自带的Apache还是XAMPP? That is a question. 其实自带的apache也够用了 ...
- CentOS 安装以及配置Apache php mysql
准备篇: 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dp ...
- Centos 下,配置 Apache + Python + Django + postgresSQL 开发环境
用 Python 搭建一个 Web 服务器 文章结构 一.安装 Apache.Python.django 二.安装 mod_wsgi,Apache 为 Python 提供的 wsgi 模块 三.将 ...
- 超详细 值得收藏 linux CentOS 7 配置Apache服务【转发+新增】
一.Apache简介 Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器软件,可以在大多数电脑操作系统中运行,由于其跨平台和安全性(尽管不断有 ...
- CentOS安装和配置Apache(httpd)
1. 安装httpd yum install httpd #安装apache 2. 启动httpd systemctl start httpd.service #启动apache 3. 随服务器自启动 ...
随机推荐
- 杂项-数学软件:Mathematica
ylbtech-杂项-数学软件:Mathematica Mathematica是一款科学计算软件,很好地结合了数值和符号计算引擎.图形系统.编程语言.文本系统.和与其他应用程序的高级连接.很多功能在相 ...
- String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转)
String.Format数字格式化输出 {:N2} {:D2} {:C2} (转) //格式为sring输出 // Label1.Text = string.Format("asdfads ...
- Go - 指针简介 与 ++/--运算符以及控制语句
指针 Go 语言中,对于指针有一些特殊约束: 1. 不在支持 “->” 符号,所有的指针使用“.” 来操作指针对象的成员变量 2. 指针的默认值为 “nil” ++ 与 -- 作为语句而非表达式 ...
- mongodb(四)
Count+Distinct+Group数据库命令操作固定集合特性GridFS文件系统补充服务器端脚本 db.runCommand({group:{ ns:"persons", k ...
- java获取取前段页面的参数
request.getParameter("tnumber") document.forms[0].s_id.value;
- MyBatis初识(通过小实例清晰认识MyBatis)
1.MyBatis框架: MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可 ...
- Redis 非关系型数据库 ( Nosql )
简介: Redis 是一个开源的,高性能的 key-value 系统,可以用来缓存或存储数据. Redis 数据可以持久化,并且支持多种数据类型:字符串(string),列表(list),哈希(has ...
- ios常用空间UIScrollViewIndicator的一些属性
UIScrollView属性: 1 alwaysBounceHorizontal BOOL值,当水平滚条到达终点,总是(视图)弹跳 2 alwaysBounceVertical ...
- Elasticsearch-PHP 概述
最近在学习使用Elasticsearch,并且是和PHP一起使用的,看到了Elasticsearch-PHP,其实是Elasticsearch为PHP提供的客户端,那么我们来学习一下API文档,如何在 ...
- mysqldump test
CREATE TABLE IF NOT EXISTS `runoob_tbl`( `runoob_id` INT UNSIGNED AUTO_INCREMENT, `runoob_title` VAR ...