☆Obaby's H4cking W0rld☆

Hack-Crack==Backdoors - RATs - Trojans // Binders-Packers - Rootkits

破解-黑客-零日漏洞-灰鸽子/上兴/PCShare-木马免杀-网站入侵-信息安全

2013年4月18日星期四

CentOS Apache 2 FastCGI

fastcgi


这几天vps又开始频繁抽风,于是给反馈了一下。然后得到的答复是可能资源耗尽了,让自己监视下。得到这个答复其实不用监视也知道是apache服务耗尽了系统内存,然后就所有的服务都失去响应了。


但是还是不想全部折腾到ngix上去,于是就想看下有没有其他的解决方案,幸运的是发现了fastcgi这个东西。换了之后系统内存立即就下来了。效果非常不错的,但是还要多跑几天看看。


安装方式:


FastCGI is a protocol for interfacing interactive programs with a web server. FastCGI’s main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests at once.


Also, PHP is not recommended with multithreaded Apache2 (worker MPM) because of performance and some 3rd party PHP extensions are not not guaranteed thread-safe.


nginx and lighttpd has inbuilt support for FastCGI. For Apache web server you need to use either mod_fastcgi or mod_fcgid.

Why use mod_fastcgi instead of mod_perl / mod_php?


From the wikipedia article:


Instead of creating a new process for every request, FastCGI can use a single persistent process which handles many requests over its lifetime. Processing of multiple requests simultaneously is achieved either by using a single connection with internal multiplexing (ie. multiple requests over a single connection) and/or by using multiple connections. Many such processes can exist, something that can increase stability and scalability. FastCGI also allows programs to get the web server to do certain simple operations, like reading in a file, before the request is handed over. Environment information and page requests are sent from the web server to the process over a TCP connection (for remote processes) or Unix domain sockets (for local processes). Responses are returned from the process to the web server over the same connection. The connection may be closed at the end of a response, but the web server and the process are left standing.

Many web site administrators and programmers are finding that the separation of web applications from the web server in FastCGI (and the simpler SCGI) has many desirable advantages over embedded interpreters (mod_perl, mod_php, etc.). This separation allows server and application processes to be restarted independently — an important consideration for busy web sites. It also facilitates per-application security policies — important for ISPs and web hosting companies.


In this quick tutorial, you will learn about Apache 2 + mod_fastcgi + PHP installation and configuration under Red Hat Enterprise Linux / CentOS Linux version 5.x+.

Install mod_fastcgi


Make sure required packages are installed (httpd-devel and apr-devel required to compile mod_fastcgi), enter:



1
# yum install libtool httpd-devel apr-devel apr


Next, grab the latest mod_fastcgi source code, enter:



1
2
# cd /opt
# wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz


Untar tar ball, type:



1
2
# tar -zxvf mod_fastcgi-current.tar.gz
# cd mod_fastcgi-2.4.6/


Make a copy of Makefile.AP2, enter:



1
# cp Makefile.AP2 Makefile


Compile and install mod_fastcgi for 32 bit system, enter:



1
2
# make top_dir=/usr/lib/httpd
# make install top_dir=/usr/lib/httpd


Compile and install mod_fastcgi for 64 bit system, enter:



1
2
# make top_dir=/usr/lib64/httpd
# make install top_dir=/usr/lib64/httpd


Sample output:



1
2
3
4
make install top_dir=/usr/lib64/httpd
make[1]: Entering directory `/tmp/mod_fastcgi-2.4.6'
/usr/lib64/apr-1/build/libtool --silent --mode=install cp mod_fastcgi.la /usr/lib64/httpd/modules/
make[1]: Leaving directory `/tmp/mod_fastcgi-2.4.6'


Configure mod_fastcgi


Open /etc/httpd/conf.d/mod_fastcgi.conf file



1
# vi /etc/httpd/conf.d/mod_fastcgi.conf


Add an entry to it like this:



1
LoadModule fastcgi_module modules/mod_fastcgi.so


Save and close the file. Restart httpd, enter:



1
# service httpd restart


Sample output:



1
2
3
4
5
6
[Mon Dec 29 23:24:44 2008] [notice] caught SIGTERM, shutting down
[Mon Dec 29 23:24:44 2008] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Dec 29 23:24:44 2008] [notice] Digest: generating secret for digest authentication ...
[Mon Dec 29 23:24:44 2008] [notice] Digest: done
[Mon Dec 29 23:24:44 2008] [notice] FastCGI: process manager initialized (pid 4785)
[Mon Dec 29 23:24:44 2008] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations


How do I configure PHP as FastCGI process under RHEL / CentOS Linux?


First, you need to disable mod_php5, enter:



1
# mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.disable


Create a shell script in cgi-bin directory called php.fcgi


Create a script as follows in /var/www/cgi-bin/php.fcgi (or put in your virtual domain cgi-bin directory)



1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI


Set permission, type:



1
# chmod +x /var/www/cgi-bin/php.fcgi


Finally, modify documentroot directory permission as follows. You need to use AddHandler and Action directives for mod_fastcgi:



1
2
3
4
5
6
7
8
9
 <directory "/var/www/html">
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
</directory>


Where,

AddHandler php5-fastcgi .php : To configure Apache to handle php files (within the scope of the directive) with the specified extension(s) as FastCGI applications.

Action php5-fastcgi /cgi-bin/php.fcgi : This directive adds an action, which will activate cgi-script when action-type is triggered by the request. The cgi-script is the URL-path to a resource that has been configured as a CGI script using ScriptAlias. In our case, requests for files with a .php file extension of are handled instead by the specified cgi script /cgi-bin/php.fcgi.


Save and close the file. Restart httpd:



1
# service httpd restart


mod_fastcgi virtual hosting configuration

Domain name: nixcraft.com

DocumentRoot: /websites/home/nixcraft.com/http

cgi-bin directory: /websites/home/nixcraft.com/cgi-bin

php.fcgi path: /websites/home/nixcraft.com/cgi-bin/php.fcgi

Logs file directory: /websites/home/nixcraft.com/logs


Based upon above settings your virtualhosting configuration for nixcraft.com domain should look like as follows:



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
<virtualhost *:80>
ServerAdmin webmaster@nixcraft.com
DocumentRoot "/websites/home/nixcraft.com/http"
ServerName nixcraft.com
ServerAlias www.nixcraft.com
ErrorLog "/websites/home/nixcraft.com/logs/error.log"
CustomLog "/websites/home/nixcraft.com/logs/access.log" common
ScriptAlias /cgi-bin/ "/websites/home/nixcraft.com/cgi-bin/"
 
<directory "/websites/home/nixcraft.com/http">
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
Order allow,deny
Allow from all
</directory>
 
<directory "/websites/home/nixcraft.com/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</directory>
</virtualhost>


Create a /websites/home/nixcraft.com/cgi-bin/php.fcgi as follows:



1
2
3
4
5
6
7
#!/bin/bash
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI


Set permission and restart httpd:



1
2
# chmod +x /websites/home/nixcraft.com/cgi-bin/php.fcgi
# service httpd restart


Link:http://www.cyberciti.biz/tips/rhel-centos-fedora-apache2-fastcgi-php-configuration.html



1 评论:

蔡翠紫 说...

糖果視頻聊天室-色非兩性網-金情社多人視頻
金情社聊天室-色吧影院美女-金情社多人視頻聊天
免費交友網站-絕對100婚戀網-金情社視頻聊天室
aio交友網站-絕對100婚戀網登錄-亂倫黃色電影小說
唐人街多人聊天視頻-蕭山富婆網-168成人電影
日本成人H漫-衣衣視頻裸聊網-快播7788電影網
伊利討論區-絕對100婚戀網首頁-Sex激情聊天室
情系晚霞聊天室-碧聊情系晚霞碧聊-叉叉叉綜合網圖片
佳吻聊天室-色吧性愛圖片性愛小說-寂寞交友富婆聊天室官網
絕對100婚戀交友網-愛幫網視頻聊天室-色人閣美女藝術圖片
絕對婚戀100會員登錄-5126社區-美女激情挑逗圖片
土豆網影片-絕對100婚戀交友-5126視頻聊天室
閃婚網-5126聊天室-性感短褲美女圖片-街拍長腿美女臀部
99cu多人視訊聊天室-亞洲第4色快播電影-亞洲電影最大色擼吧
閃婚網網址-久久舞吧視頻聊天室-色波霸影院人妻
美女舞廳視頻聊天社區-老色驢經典影院-浪起來綜合影院
百姓閃婚網-美女舞廳視頻聊天室-色七七影視
遼河聊吧語音視頻聊天室-色七七影院在線-奇悅社區視頻聊天室
99770在線漫畫-77情緣網-潮人街視頻社區-mm625成人電影網
99漫畫網-尋歡網-潮人街視頻聊天室-大波妹影院在線觀看
太原尋歡網-股票聊天室-大波妹影院肉感-色誘影院頻道
打飛機專用-石家莊尋歡網-衡水網絡情緣聊天室
青島尋歡網-衡水視頻聊天室-色誘影院電影
包頭洗浴尋歡網-91KShow娛樂社區-色誘閣影院
夜夜尋歡網上海-91KShow視頻聊天室-宅男色影音
打飛機-夜生活網-聖魔男女SM聊天室-色女孩綜合
武漢夜生活網-愛聊江蘇地區聊天室-大波妹成人影視
男女交友聊天網-南寧夜生活網-夜色99百人視頻聊天室
免費交友聊天網-夜色88百人視頻聊天室-帝成聊天室吧
愛情聊-快播大波妹影院在線觀看-老熟妻影院
愛情聊視頻聊天室-瘋牛快播電影院-色窩窩成人電影
愛情聊視頻社區-快播電影色窩-彩蓮公主聊天室
乳源交友-西安富婆包養網-色窩在線電影
寂寞人交友網-中國比基尼美女視頻-色護士影院觀看
日本深夜綜藝節目線上看-日冰寂寞同城交友網
日本深夜綜藝節目-hihi寂寞同城交友網-六間房直播房間
真情在線婚戀網-好聊天室女視頻聊-六間房直播現場
麗的情遊戲-朵朵同城交友網-六間房美女秀場直播
同城真人美女寂寞交友-寂寞sm直播間-六間房直播跳舞
有什麼免費的色聊網-六間房視頻直播DJ-七仙女裸聊吧
真情在線婚戀網吧-真人在線裸聊網-六間房視頻下載
麗的情色遊戲-虫族同城夜情交友網-同城約會交友e夜情
4758寂寞同城交友-歪歪裸聊-台灣佬夫妻娛樂網小說
真情在線-天天色綜合圖-台灣佬中文夫妻娛樂網
風雪英雄情緣聊天室-真實性生活視頻-台灣妹中文娛樂網

发表评论