fedora x64
配置nginx
- location / {
-
root /home/mass/www;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index;
-
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
-
include fastcgi_params;
-
}
主要的是要指定fastcgi_pass 意味着把web请求重定向到这个地址
测试用fastcgi,echo.c来自fastcgi.com,编译
- gcc -o echo -lfcgi echo.c
然后执行
- spawn-fcgi -a 127.0.0.1 -p 9000 -f ./echo
spawn-fcgi是一个执行fastcgi程序的程序,fedora 可以通过yum install spawn-fcgi安装
之后通过浏览器访问
结果如下:
- Request environment:
-
-
FCGI_ROLE=RESPONDER
-
SCRIPT_FILENAME=/scripts/hello
-
QUERY_STRING=
-
REQUEST_METHOD=GET
-
CONTENT_TYPE=
-
CONTENT_LENGTH=
-
SCRIPT_NAME=/hello
-
REQUEST_URI=/hello
-
DOCUMENT_URI=/hello
-
DOCUMENT_ROOT=/home/mass/www
-
SERVER_PROTOCOL=HTTP/1.1
-
GATEWAY_INTERFACE=CGI/1.1
-
SERVER_SOFTWARE=nginx/0.8.53
-
REMOTE_ADDR=127.0.0.1
-
REMOTE_PORT=48805
-
SERVER_ADDR=127.0.0.1
-
SERVER_PORT=80
-
SERVER_NAME=_
-
REDIRECT_STATUS=200
-
HTTP_HOST=localhost
-
HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20100101 Firefox/4.0
-
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
-
HTTP_ACCEPT_LANGUAGE=zh-cn,zh;q=0.5
-
HTTP_ACCEPT_ENCODING=gzip, deflate
-
HTTP_ACCEPT_CHARSET=GB2312,utf-8;q=0.7,*;q=0.7
-
HTTP_KEEP_ALIVE=115
-
HTTP_CONNECTION=keep-alive
-
HTTP_COOKIE=__utma=111872281.1435764372.1302411201.1302523107.1302525975.3; __utmz=111872281.1302411201.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
-
HTTP_CACHE_CONTROL=max-age=0
可以看到,当访问的路径是/hello时,环境变量SCRIPT_NAME,REQUEST_URI,DOCUMENT_URI均为/hello.
nginx 内置的环境变量在/etc/nginx/fastcgi.conf中
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
fastcgi_param QUERY_STRING $query_string;
-
fastcgi_param REQUEST_METHOD $request_method;
-
fastcgi_param CONTENT_TYPE $content_type;
-
fastcgi_param CONTENT_LENGTH $content_length;
-
-
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
-
fastcgi_param REQUEST_URI $request_uri;
-
fastcgi_param DOCUMENT_URI $document_uri;
-
fastcgi_param DOCUMENT_ROOT $document_root;
-
fastcgi_param SERVER_PROTOCOL $server_protocol;
-
-
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
-
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
-
-
fastcgi_param REMOTE_ADDR $remote_addr;
-
fastcgi_param REMOTE_PORT $remote_port;
-
fastcgi_param SERVER_ADDR $server_addr;
-
fastcgi_param SERVER_PORT $server_port;
-
fastcgi_param SERVER_NAME $server_name;
-
-
# PHP only, required if PHP was built with --enable-force-cgi-redirect
-
fastcgi_param REDIRECT_STATUS 200;
阅读(3547) | 评论(0) | 转发(0) |