[nginx] nginx_http_dwsgi_module 配置说明

nginx_http_dwsgi_module 改自 fastcgi module, 它的配置和 fastcgi 很像, 但选项更少一些, 指令名称由 fastcgi_xxxx 改变为 dwsgi_xxx
下面列出常用的指令及其异同,详细可参见 fastcgi 的官方配置WIKI.

一、各项指令及异同说明
1. dwsgi_pass 参见 fastcgi_pass
基本一致, 但如果传入的参数不是 unix: 开头的套接字地址或者命名的upstream列表中未包含unix:套接字的将在运行时
产生错误, 直接返回 500 internal server error
2. dwsgi_index 参见 fastcgi_index
3. dwsgi_split_path_info 参见 fastcgi_split_path_info

4. dwsgi_connect_timeout 参见 fastcgi_connect_timeout
dwsgi_send_timeout 参见 fastcgi_send_timeout
dwsgi_read_timeout 参见 fastcgi_read_timeout
默认值调为 6秒而不是60秒

5. dwsgi_buffer_size 参见 fastcgi_buffer_size
dwsgi_pass_request_headers 参见 fastcgi_pass_request_headers
dwsgi_buffers 参见 fastcgi_buffers
dwsgi_busy_buffers_size 参见 fastcgi_busy_buffers_size
dwsgi_param 参见 fastcgi_param

6. dwsgi_next_upstrem 参见 fastcgi_next_upstream
去掉支持 http_404 http_503 http_500

二、典型配置案例 (也可用作 fastcgi 配置, 🙂

1. 把参数和通用选项存入 dwsgi.conf

## DWSGI/PHP-dws
##
dwsgi_pass unix:/tmp/php-dws.sock;
dwsgi_param SCRIPT_FILENAME $document_root$dwsgi_script_name;
dwsgi_param PATH_INFO $dwsgi_path_info;
dwsgi_param QUERY_STRING $query_string;
dwsgi_param REQUEST_METHOD $request_method;
dwsgi_param CONTENT_TYPE $content_type;
dwsgi_param CONTENT_LENGTH $content_length;

dwsgi_param SCRIPT_NAME $dwsgi_script_name;
dwsgi_param REQUEST_URI $request_uri;
dwsgi_param DOCUMENT_URI $document_uri;
dwsgi_param DOCUMENT_ROOT $document_root;
dwsgi_param SERVER_PROTOCOL $server_protocol;

dwsgi_param GATEWAY_INTERFACE CGI/1.1;
dwsgi_param SERVER_SOFTWARE nginx/$nginx_version;

dwsgi_param REMOTE_ADDR $remote_addr;
dwsgi_param REMOTE_PORT $remote_port;
dwsgi_param SERVER_ADDR $server_addr;
dwsgi_param SERVER_PORT $server_port;
dwsgi_param SERVER_NAME $server_name;
## File END

2. locations 的配置示范:

## PHP scripts
location ~ \.php$ {
if (-d $request_filename) {
rewrite ^ $uri/ redirect;
}
if (!-f $request_filename) {
return 404;
}
include dwsgi.conf;
}

## PHP with pathinfo
location ~ \.php/ {
try_files $uri $uri/ @dwsgi;
}

## DwsCGI handler
location @dwsgi {
dwsgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$dwsgi_script_name) {
return 404;
}
include dwsgi.conf;
}

三、重启nginx服务即可, 如果需要兼容同时运行 php-fastcgi 和 php-dws 可以给 php-dws 指定一个新的后缀名来配置, 比如 .phpd

发表评论

电子邮件地址不会被公开。 必填项已用*标注