这篇文章主要为大家详细介绍了CentOS 7.2配置Apache服务 httpd上篇,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
一、Perl + mod_perl
安装mod_perl使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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
[root@linuxprobe ~]
# yum --enablerepo=epel -y install mod_perl
[2] 配置PerlRun模式,总是将Perl解释器放在RAM上。
# vi /etc/httpd/conf.d/perl.conf
# line 15: 取消注释 ( check codes and output warnings to logs )
PerlSwitches -w
# line 24: 取消注释
PerlSwitches -T
# line 30-36: 取消注释像下面一样
Alias
/perl
/var/www/perl
<Directory
/var/www/perl
>
# the directory for mod_perl environment
SetHandler perl-script
# processes files as perl-scripts under this directory
# AddHandler perl-script .cgi
# set specific extension if do do not want to processes all files as CGI
# PerlResponseHandler ModPerl::Registry
PerlResponseHandler ModPerl::PerlRun
# specify PerlRun mode
PerlOptions +ParseHeaders
Options +ExecCGI
<
/Directory
>
# line 43-49: 取消注释并添加如下信息
<Location
/perl-status
>
SetHandler perl-script
PerlResponseHandler Apache2::Status
Require ip 127.0.0.1 10.1.1.1
/24
# add access permission
# Order deny,allow
# Deny from all
# Allow from .example.com
/Location
>
# systemctl restart httpd
[3] 创建测试脚本以确保设置不是ploblem。如果显示如下所示的结果,就可以。
# mkdir /var/www/perl
# vi /var/www/perl/test-mod_perl.cgi
#!/usr/bin/perl
use strict;
use warnings;
print
"Content-type: text/html\n\n"
;
"<html>\n<body>\n"
;
"<div style=\"width:100%; font-size:40px; font-weight:bold; text-align:center;\">"
;
my $a = 0;
&number();
"</div>\n</body>\n</html>"
;
sub number {
$a++;
"number \$a = $a"
;
}
# chmod 705 /var/www/perl/test-mod_perl.cgi
|
13
/var/www/perl
>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
# uncomment
#
PerlResponseHandler ModPerl::PerlRun
# comment out
PerlOptions +ParseHeaders
Options +ExecCGI
>
# systemctl restart httpd
[5] 访问作为[4]节的示例的测试脚本,然后变量通过重新加载而增加,因为变量被高速缓存在RAM上。所以有必要编辑注册表模式的代码,这里浏览器没刷新一次,$a值加一。
25
#!/usr/bin/perl
use strict;
use warnings;
;
;
;
my $a = 0;
&number($a
);
;
sub number {
my($a) = @_;
$a++;
;
}
[6]顺便说一下,可以看到mod_perl的状态来访问“http://(主机名或IP地址)/ perl-status”。
18
[2]安装PHP-FPM。
# yum -y install PHP-fpm
[3] 配置Apache httpd。
# vi /etc/httpd/conf.d/PHP.conf
# line 5: change like follows
<FilesMatch \.PHP$>
#
SetHandler application
/x-httpd-PHP
SetHandler
"proxy:fcgi://127.0.0.1:9000"
/FilesMatch
# systemctl start PHP-fpm
# systemctl enable PHP-fpm
# systemctl restart httpd
三、Python + mod_wsgi
安装mod_wsgi(WSGI:Web服务器网关接口),使Python脚本更快
[2] 例如,将mod_wsgi配置为可以访问/ test_wsgi,后端是
/var/www/html/test_wsgi
.py.
# vi /etc/httpd/conf.d/wsgi.conf
# create new
WSGIScriptAlias
/test_wsgi
/var/www/html/test_wsgi
.py
# systemctl restart httpd
[3] 创建您在上面设置的测试脚本.
# vi /var/www/html/test_wsgi.py
# create new
def application(environ,start_response):
status =
'200 OK'
html =
'<html>\n'
\
'<body>\n'
\
'<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n'
\
'mod_wsgi Test Page\n'
\
'</div>\n'
\
'</body>\n'
\
'</html>\n'
response_header = [(
'Content-type'
,
'text/html'
)]
start_response(status,response_header)
return
[html]