php cgi模块,LNMP 方案之使用 HevSCGIServer CGI 模块连接 Nginx 和 PHP-CGI

5ce207ea79b14c0e66af81647a8e62bc.png

HevSCGIServer CGI 模块可用于实现 SCGI 协议转 CGI 协议,执行 CGI 程序。它将通过创建子进程的方式执行 CGI 程序,在进程间通信方式上是将 socket 映射到 standard i/o,有着比较优秀的性能,同时对内存需求也比较小,适合虚拟主机方案使用。

Nginx 配置文件

# vhost

# Heiher

# HTTP Server

server {

listen 80; ## listen for ipv4

server_name localhost;

access_log /var/web/USERNAME/home/web/logs/access.log;

error_log /var/web/USERNAME/home/web/logs/error.log;

location / {

root /var/web/USERNAME/home/web/www;

index index.html index.htm index.php;

## Rewrite

if (!-e $request_filename)

{

rewrite ^(.+)$ /index.php?q=$1 last;

}

omallow USERNAME sftp; # 允许访问隶属于 USERNAME:sftp 的文件

omdeny all; # 禁止访问其它所有文件

}

# pass the PHP scripts to FastCGI server listening on socket file

#

location ~ \.php$ {

if (!-e $request_filename) {

return 404;

}

scgi_pass unix:/var/web/USERNAME/run/hev-scgi-server.sock;

scgi_param REDIRECT_STATUS 200;

scgi_param SCRIPT_FILE /usr/bin/php-cgi;

scgi_param SCRIPT_FILENAME /var/web/USERNAME/home/web/www/$document_uri;

include scgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /\.ht {

deny all;

}

}

# HTTPS Server

server {

listen 443; ## listen for ipv4

server_name localhost;

ssl on;

ssl_certificate /var/web/USERNAME/cert/cert.pem;

ssl_certificate_key /var/web/USERNAME/cert/cert.key;

ssl_session_timeout 5m;

ssl_protocols SSLv3 TLSv1;

ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;

ssl_prefer_server_ciphers on;

access_log /var/web/USERNAME/home/web/logs/access.log;

error_log /var/web/USERNAME/home/web/logs/error.log;

location / {

root /var/web/USERNAME/home/web/www;

index index.html index.htm index.php;

## Rewrite

if (!-e $request_filename)

{

rewrite ^(.+)$ /index.php?q=$1 last;

}

omallow USERNAME sftp;

omdeny all;

}

# pass the PHP scripts to FastCGI server listening on socket file

#

location ~ \.php$ {

if (!-e $request_filename) {

return 404;

}

scgi_pass unix:/var/web/USERNAME/run/hev-scgi-server.sock;

scgi_param REDIRECT_STATUS 200;

scgi_param SCRIPT_FILE /usr/bin/php-cgi;

scgi_param SCRIPT_FILENAME /var/web/USERNAME/home/web/www/$document_uri;

scgi_param HTTPS on;

include scgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /\.ht {

deny all;

}

}

# vhost

# Heiher

# HTTP Server

server {

listen 80; ## listen for ipv4

server_name localhost;

access_log /var/web/USERNAME/home/web/logs/access.log;

error_log /var/web/USERNAME/home/web/logs/error.log;

location / {

root /var/web/USERNAME/home/web/www;

index index.html index.htm index.php;

## Rewrite

if (!-e $request_filename)

{

rewrite ^(.+)$ /index.php?q=$1 last;

}

omallow USERNAME sftp; # 允许访问隶属于 USERNAME:sftp 的文件

omdeny all; # 禁止访问其它所有文件

}

# pass the PHP scripts to FastCGI server listening on socket file

#

location ~ \.php$ {

if (!-e $request_filename) {

return 404;

}

scgi_pass unix:/var/web/USERNAME/run/hev-scgi-server.sock;

scgi_param REDIRECT_STATUS 200;

scgi_param SCRIPT_FILE /usr/bin/php-cgi;

scgi_param SCRIPT_FILENAME /var/web/USERNAME/home/web/www/$document_uri;

include scgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /\.ht {

deny all;

}

}

# HTTPS Server

server {

listen 443; ## listen for ipv4

server_name localhost;

ssl on;

ssl_certificate /var/web/USERNAME/cert/cert.pem;

ssl_certificate_key /var/web/USERNAME/cert/cert.key;

ssl_session_timeout 5m;

ssl_protocols SSLv3 TLSv1;

ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;

ssl_prefer_server_ciphers on;

access_log /var/web/USERNAME/home/web/logs/access.log;

error_log /var/web/USERNAME/home/web/logs/error.log;

location / {

root /var/web/USERNAME/home/web/www;

index index.html index.htm index.php;

## Rewrite

if (!-e $request_filename)

{

rewrite ^(.+)$ /index.php?q=$1 last;

}

omallow USERNAME sftp;

omdeny all;

}

# pass the PHP scripts to FastCGI server listening on socket file

#

location ~ \.php$ {

if (!-e $request_filename) {

return 404;

}

scgi_pass unix:/var/web/USERNAME/run/hev-scgi-server.sock;

scgi_param REDIRECT_STATUS 200;

scgi_param SCRIPT_FILE /usr/bin/php-cgi;

scgi_param SCRIPT_FILENAME /var/web/USERNAME/home/web/www/$document_uri;

scgi_param HTTPS on;

include scgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /\.ht {

deny all;

}

}

HevSCGIServer 编译安装

1. 下载源代码

mkdir hev-scgi-server-framework

cd hev-scgi-server-framework

git clone git://gitcafe.com/heiher/hev-scgi-server-library.git

git clone git://gitcafe.com/heiher/hev-scgi-server.git

git clone git://gitcafe.com/heiher/hev-scgi-server-cgi.git

mkdir hev-scgi-server-framework

cd hev-scgi-server-framework

git clone git://gitcafe.com/heiher/hev-scgi-server-library.git

git clone git://gitcafe.com/heiher/hev-scgi-server.git

git clone git://gitcafe.com/heiher/hev-scgi-server-cgi.git

2. 编译

cd hev-scgi-server-library

make

cd ..

cd hev-scgi-server

make

cd ..

cd hev-scgi-server-cgi

make

cd ..

cd hev-scgi-server-library

make

cd ..

cd hev-scgi-server

make

cd ..

cd hev-scgi-server-cgi

make

cd ..

3. 安装

mkdir -p /opt/hev-scgi-server/{bin,conf,modules}

cp hev-scgi-server/bin/* hev-scgi-server-library/bin/* /opt/hev-scgi-server/bin/

cp hev-scgi-server-cgi/bin/* /opt/hev-scgi-server/modules/

cp hev-scgi-server/conf/main.conf /opt/hev-scgi-server/conf/

mkdir -p /opt/hev-scgi-server/{bin,conf,modules}

cp hev-scgi-server/bin/* hev-scgi-server-library/bin/* /opt/hev-scgi-server/bin/

cp hev-scgi-server-cgi/bin/* /opt/hev-scgi-server/modules/

cp hev-scgi-server/conf/main.conf /opt/hev-scgi-server/conf/

HevSCGIServer 配置

conf/main.conf

[Server]

Address=unix:/var/web/USERNAME/run/hev-scgi-server.sock

ModuleDirPath=./modules

[Server]

Address=unix:/var/web/USERNAME/run/hev-scgi-server.sock

ModuleDirPath=./modules

conf/modules.conf

[Module0]

Alias=HevSCGIHandlerPHP

Pattern=.*

FileName=libhev-scgi-server-cgi.so

CGIBinPath=/usr/bin/php-cgi

WorkDir=/var/web/USERNAME/home/web/www

[Module0]

Alias=HevSCGIHandlerPHP

Pattern=.*

FileName=libhev-scgi-server-cgi.so

CGIBinPath=/usr/bin/php-cgi

WorkDir=/var/web/USERNAME/home/web/www

/etc/rc.local

# HevSCGIServer

cd /opt/hev-scgi-server/

rm -f /var/web/USERNAME/run/hev-scgi-server.sock

LD_LIBRARY_PATH=/opt/hev-scgi-server/bin /opt/hev-scgi-server/bin/hev-scgi-server -u USERNAME -g GROUP

chmod 0666 /var/web/USERNAME/run/hev-scgi-server.sock

# HevSCGIServer

cd /opt/hev-scgi-server/

rm -f /var/web/USERNAME/run/hev-scgi-server.sock

LD_LIBRARY_PATH=/opt/hev-scgi-server/bin /opt/hev-scgi-server/bin/hev-scgi-server -u USERNAME -g GROUP

chmod 0666 /var/web/USERNAME/run/hev-scgi-server.sock

Over!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值