Chinaunix首页 | 论坛 | 博客
  • 博客访问: 456733
  • 博文数量: 64
  • 博客积分: 3271
  • 博客等级: 中校
  • 技术积分: 727
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-30 18:42
文章分类

全部博文(64)

文章存档

2013年(1)

2011年(19)

2010年(42)

2009年(2)

分类: C/C++

2011-04-12 22:22:20

fedora x64
配置nginx

  1. location / {
  2. root /home/mass/www;
  3. fastcgi_pass 127.0.0.1:9000;
  4. fastcgi_index index;
  5. fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  6. include fastcgi_params;
  7. }
主要的是要指定fastcgi_pass 意味着把web请求重定向到这个地址
测试用fastcgi,echo.c来自fastcgi.com,编译
  1. gcc -o echo -lfcgi echo.c
然后执行
  1. spawn-fcgi -a 127.0.0.1 -p 9000 -f ./echo
spawn-fcgi是一个执行fastcgi程序的程序,fedora 可以通过yum install spawn-fcgi安装

之后通过浏览器访问
结果如下:
  1. Request environment:

  2. FCGI_ROLE=RESPONDER
  3. SCRIPT_FILENAME=/scripts/hello
  4. QUERY_STRING=
  5. REQUEST_METHOD=GET
  6. CONTENT_TYPE=
  7. CONTENT_LENGTH=
  8. SCRIPT_NAME=/hello
  9. REQUEST_URI=/hello
  10. DOCUMENT_URI=/hello
  11. DOCUMENT_ROOT=/home/mass/www
  12. SERVER_PROTOCOL=HTTP/1.1
  13. GATEWAY_INTERFACE=CGI/1.1
  14. SERVER_SOFTWARE=nginx/0.8.53
  15. REMOTE_ADDR=127.0.0.1
  16. REMOTE_PORT=48805
  17. SERVER_ADDR=127.0.0.1
  18. SERVER_PORT=80
  19. SERVER_NAME=_
  20. REDIRECT_STATUS=200
  21. HTTP_HOST=localhost
  22. HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20100101 Firefox/4.0
  23. HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  24. HTTP_ACCEPT_LANGUAGE=zh-cn,zh;q=0.5
  25. HTTP_ACCEPT_ENCODING=gzip, deflate
  26. HTTP_ACCEPT_CHARSET=GB2312,utf-8;q=0.7,*;q=0.7
  27. HTTP_KEEP_ALIVE=115
  28. HTTP_CONNECTION=keep-alive
  29. HTTP_COOKIE=__utma=111872281.1435764372.1302411201.1302523107.1302525975.3; __utmz=111872281.1302411201.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
  30. HTTP_CACHE_CONTROL=max-age=0
可以看到,当访问的路径是/hello时,环境变量SCRIPT_NAME,REQUEST_URI,DOCUMENT_URI均为/hello.

nginx 内置的环境变量在/etc/nginx/fastcgi.conf中
  1. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  2. fastcgi_param QUERY_STRING $query_string;
  3. fastcgi_param REQUEST_METHOD $request_method;
  4. fastcgi_param CONTENT_TYPE $content_type;
  5. fastcgi_param CONTENT_LENGTH $content_length;

  6. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  7. fastcgi_param REQUEST_URI $request_uri;
  8. fastcgi_param DOCUMENT_URI $document_uri;
  9. fastcgi_param DOCUMENT_ROOT $document_root;
  10. fastcgi_param SERVER_PROTOCOL $server_protocol;

  11. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  12. fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

  13. fastcgi_param REMOTE_ADDR $remote_addr;
  14. fastcgi_param REMOTE_PORT $remote_port;
  15. fastcgi_param SERVER_ADDR $server_addr;
  16. fastcgi_param SERVER_PORT $server_port;
  17. fastcgi_param SERVER_NAME $server_name;

  18. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  19. fastcgi_param REDIRECT_STATUS 200;




阅读(3541) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~