前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS 7.2 配置Apache服务(httpd)--下篇

CentOS 7.2 配置Apache服务(httpd)--下篇

作者头像
shaonbean
发布2019-05-26 09:41:53
4400
发布2019-05-26 09:41:53
举报
文章被收录于专栏:运维前线运维前线

版权声明:本文为木偶人shaon原创文章,转载请注明原文地址,非常感谢。 https://cloud.tencent.com/developer/article/1434718

一、Perl + mod_perl

  • 安装mod_perl使Perl脚本速度快
代码语言:javascript
复制
[1]  安装mod_perl
# 从EPEL安装
[root@linuxprobe ~]# yum --enablerepo=epel -y install mod_perl
[2]  配置PerlRun模式,总是将Perl解释器放在RAM上。  
[root@linuxprobe ~]# 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>
[root@linuxprobe ~]# systemctl restart httpd

[3]  创建测试脚本以确保设置不是ploblem。如果显示如下所示的结果,就可以。  
[root@linuxprobe ~]# mkdir /var/www/perl
[root@linuxprobe ~]# vi /var/www/perl/test-mod_perl.cgi

#!/usr/bin/perl

use strict;
use warnings;

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;\">";

my $a = 0;
&number();

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

sub number {
    $a++;
    print "number \$a = $a";
}

[root@linuxprobe ~]# chmod 705 /var/www/perl/test-mod_perl.cgi 
#客户端浏览器访问:http://linuxprobe.org/perl/test-mod_perl.cgi
代码语言:javascript
复制
[4]  配置在RAM上具有代码缓存的注册表模式
[root@linuxprobe ~]# vi /etc/httpd/conf.d/perl.conf
Alias /perl /var/www/perl
<Directory /var/www/perl>
    SetHandler perl-script
    PerlResponseHandler ModPerl::Registry # uncomment

#
   PerlResponseHandler ModPerl::PerlRun # comment out

    PerlOptions +ParseHeaders
    Options +ExecCGI
</Directory>
[root@linuxprobe ~]# systemctl restart httpd 
代码语言:javascript
复制
[5] 访问作为[4]节的示例的测试脚本,然后变量通过重新加载而增加,因为变量被高速缓存在RAM上。所以有必要编辑注册表模式的代码,这里浏览器没刷新一次,$a值加一。
代码语言:javascript
复制
[root@linuxprobe ~]# vi /var/www/perl/test-mod_perl.cgi

#!/usr/bin/perl

use strict;
use warnings;

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;\">";

my $a = 0;

&number($a
);

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

sub number {

    my($a) = @_;

    $a++;
    print "number \$a = $a";
}
代码语言:javascript
复制
[6]顺便说一下,可以看到mod_perl的状态来访问“http://(主机名或IP地址)/ perl-status”。 

二、PHP + PHP-FPM

  • 安装PHP-FPM使PHP脚本速度快
代码语言:javascript
复制
[1]安装PHP,请参考这里。     
[2]安装PHP-FPM。   
[root@linuxprobe ~]# yum -y install php-fpm
[3]     配置Apache httpd。
[root@linuxprobe ~]# 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>
[root@linuxprobe ~]# systemctl start php-fpm
[root@linuxprobe ~]# systemctl enable php-fpm
[root@linuxprobe ~]# systemctl restart httpd

[4]创建phpinfo并访问它,然后如果“FPM / FastCGI”显示,它是确定。    
[root@linuxprobe ~]# echo '<?php phpinfo(); ?>' > /var/www/html/info.php 

三、Python + mod_wsgi

  • 安装mod_wsgi(WSGI:Web服务器网关接口),使Python脚本更快
代码语言:javascript
复制
[1] 安装mod_wsgi  .
[root@linuxprobe ~]# yum -y install mod_wsgi
[2] 例如,将mod_wsgi配置为可以访问/ test_wsgi,后端是/var/www/html/test_wsgi.py.
[root@linuxprobe ~]# vi /etc/httpd/conf.d/wsgi.conf
# create new

WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py
[root@linuxprobe ~]# systemctl restart httpd

[3] 创建您在上面设置的测试脚本.
[root@linuxprobe ~]# 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]
代码语言:javascript
复制
[4]配置如果你使用Django。 ([参考安装Django](http://blog.csdn.net/wh211212/article/details/52992413))例如,在“wang”下拥有的“/home/wang/ venv/testproject”下配置“testapp”

[root@linuxprobe ~]# vi /etc/httpd/conf.d/django.conf
# create new

WSGIDaemonProcess testapp python-path=/home/wang/venv/testproject:/home/wang/venv/lib/python2.7/site-packages
WSGIProcessGroup testapp
WSGIScriptAlias /django /home/wang/venv/testproject/testproject/wsgi.py

<Directory /home/wang/venv/testproject>
    Require all granted
</Directory>

[root@linuxprobe ~]# systemctl restart httpd 

四、访问日志分析器:AWstats

  • 安装AWstats,它报告http日志以分析对http服务器的访问。
代码语言:javascript
复制
[1] 安装AWstats。  
# install from EPEL
[root@linuxprobe ~]# yum --enablerepo=epel -y install awstats
# awstats.(hostname).conf是自动生成的
[root@linuxprobe ~]# vi /etc/awstats/awstats.linuxprobe.org.conf
# line 122: change
# if your config for log format in httpd.conf is 'combined' Set here '1'
# If log-config is 'common' set here '4', but in this case, some informations can't be get (browser info and so on)
LogFormat=1
# line 153: specify your hostname
SiteDomain="linuxprobe.org
# line 168: set IP address you'd like to exclude
HostAliases="localhost 127.0.0.1 REGEX[server\.world$] REGEX[^10\.1\.1\.]
"
[root@linuxprobe ~]# vi /etc/httpd/conf.d/awstats.conf
# line 30: IP address you permit to access
Require ip 10.1.1.0/24

[root@linuxprobe ~]# systemctl restart httpd
# generate reports ( reports are updated for hourly by Cron )

[root@linuxprobe ~]# /usr/share/awstats/linuxproberoot/cgi-bin/awstats.pl -config=linuxprobe.org -update

Create/Update database for config "/etc/awstats/awstats.linuxprobe.org.conf" by AWStats version 7.4 (build 20150714)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 165
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 165 new qualified records.
代码语言:javascript
复制
[2]访问“http://(您的服务器的名称或IP地址/)/awstats/awstats.pl”,然后显示以下屏幕,可以看到httpd日志报告。
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年11月01日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、Perl + mod_perl
  • 二、PHP + PHP-FPM
  • 三、Python + mod_wsgi
  • 四、访问日志分析器:AWstats
相关产品与服务
Elasticsearch Service
腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档