一、Perl + mod_perl
安裝mod_perl使Perl指令碼速度快
[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/perluse 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
[4] 配置在RAM上具有代碼緩衝的註冊表模式
[root@linuxprobe ~]# vi /etc/httpd/conf.d/perl.confAlias /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
[5] 訪問作為[4]節的樣本的測試指令碼,然後變數通過重新載入而增加,因為變數被快取在RAM上。所以有必要編輯註冊表模式的代碼,這裡瀏覽器沒重新整理一次,$a值加一。
[root@linuxprobe ~]# vi /var/www/perl/test-mod_perl.cgi#!/usr/bin/perluse 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";}
[6]順便說一下,可以看到mod_perl的狀態來訪問“http://(主機名稱或IP地址)/ perl-status”。
二、PHP + PHP-FPM
安裝PHP-FPM使PHP指令碼速度快
[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指令碼更快
[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 newWSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py[root@linuxprobe ~]# systemctl restart httpd[3] 建立您在上面設定的測試指令碼.[root@linuxprobe ~]# vi /var/www/html/test_wsgi.py# create newdef 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]
[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 newWSGIDaemonProcess testapp python-path=/home/wang/venv/testproject:/home/wang/venv/lib/python2.7/site-packagesWSGIProcessGroup testappWSGIScriptAlias /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伺服器的訪問。
[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 hostnameSiteDomain="linuxprobe.org# line 168: set IP address you'd like to excludeHostAliases="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 accessRequire 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 -updateCreate/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: 0Parsed 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.
[2]訪問“http://(您的伺服器的名稱或IP地址/)/awstats/awstats.pl”,然後顯示以下螢幕,可以看到httpd日誌報告。
以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。