freebsd 安装nginx

 利用Nginx替代apache实现高性能的Web环境 ,在freebsd下的安装更是方便,
一 . 安装必备软件
MySQL+PHP+Pcre
cd /usr/ports/database/mysql50-server && make install clean
cd /usr/lang/php5/ && make install clean 选择对cgi mysql等的支持
cd /usr/devel/pcre && make install clean

用ports安装 /usr/ports/www/nginx, make install clean

二、弄了一个fastcgi的脚本,来自lighttpd
1) cd /usr/ports/www/lighttpd
2) make
3) cp /usr/ports/www/lighttpd/work/lighttpd-1.4.18/src/spawn-cgi /usr/bin
4) make clean
三、修改配置文件:
1,/usr/local/etc/nginx/nginx.conf:

  1. user  www www;
  2. worker_processes 10;
  3. error_log  /usr/local/etc/nginx/logs/nginx_error.log
  4. events
  5. {
  6.       use kqueue;
  7.       worker_connections 51200;
  8. }
  9. http
  10. {
  11.       include       conf/mime.types;
  12.       default_type  application/octet-stream;
  13.       charset  gb2312;
  14.       server_names_hash_bucket_size 128;
  15.       keepalive_timeout 60;
  16.       tcp_nodelay on;
  17.       gzip on;
  18.       gzip_min_length  1k;
  19.       gzip_buffers     4 8k;
  20.       gzip_http_version 1.1;
  21.       gzip_types       text/plain application/x-javascript. text/css text/html application/xml;
  22.       server
  23.       {
  24.               listen       80;
  25.               server_name  www.jianblog.com;
  26.               index index.html index.htm index.php;
  27.               root  /usr/local/www/data/;
  28.               location ~ .*\.php?$
  29.               {
  30.                    include fcgi.conf;     
  31.                    fastcgi_pass  127.0.0.1:9000;
  32.                    fastcgi_index index.php;
  33.               }
  34.  
  35.               log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
  36.                                     '$status $body_bytes_sent "$http_referer" '
  37.                                     '"$http_user_agent" $http_x_forwarded_for';
  38.               access_log  /usr/local/nginx/logs/access.log  access;
  39.       }
  40.  
  41.     }
  42.  
  43.  
  44. 2 ,先将php.ini的配置中
  45.  
  46.  
  47. cgi.fix_pathinfo=1 这样php-cgi方能正常使用SCRIPT_FILENAME这个变量。
  48.  
  49.  
  50. 3,编辑fcgi.conf文件,加入
  51.  
  52. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  53. fastcgi_param  SERVER_SOFTWARE    nginx;
  54.  
  55. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
  56. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  57. #fastcgi_param  REDIRECT_STATUS    200;

四,启动
1, 启动fcgi
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/local/bin/php-cgi
参数说明:
-f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
-a 绑定到地址addr
-p 绑定到端口port
-s 绑定到unix socket的路径path
-C 指定产生的FastCGI的进程数,默认为5(仅用于PHP)
-P 指定产生的进程的PID文件路径
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/local/bin/php-cgi

RSS feed for comments on this post · TrackBack URL

发表评论

You must be logged in to post a comment.