linux 下 nginx phpcgi 的安装及配置
| 
                         一,什么是nginx,它有什么优点 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。
Nginx 是一个很牛的高性能Web和反向代理服务器,它具有有很多非常优越的特性: 
 二,安装所要软件 wget http://sysoev.ru/nginx/nginx-0.8.15.tar.gz wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz wget http://museum.php.net/php5/php-5.2.6.tar.gz 三、安装PHP 5.2.6(FastCGI模式) 安装php的时候,需要安装支持php的一些库,不过一般情况,装好linux系统时,这些库基本上都装好,所以支持php安装的软件,就在这儿不说了。如果make && make install时提示出错时,你可以看一下缺少什么,你就装什么。 tar zxvf php-5.2.6.tar.gz make && make install cp /usr/local/php/bin/php? /usr/bin/php-cgi 1,修改php.ini nano php.ini? 按f6然后输入extension_dir 查找/usr/local/php/etc/php.ini中的extension_dir = "./" 2,启动php-cgi /usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -f /usr/bin/php-cgi nginx配置文件中的? fastcgi_pass 127.0.0.1:9000; 就是根据上面来的 3,查看一下 [zhangy@BlackGhost www]$ ps -e|grep php-cgi 四,安装nginx tar zxvf nginx-0.8.35.tar.gz 1,配置nginx.conf nano /usr/local/nginx/conf/nginx.conf user  zhangy users;
worker_processes 10;
error_log  /var/vlogs/nginx_error.log  crit;
pid        /var/vlogs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
http
{
  include       mime.types;
  default_type  application/octet-stream;
  #charset  gb2312;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
  sendfile on;
  tcp_nopush     on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
  #limit_zone  crawler  $binary_remote_addr  10m;
    upstream 127.0.0.1:1081  { server 127.0.0.1:1081; }
    upstream localhost:1080 { server 127.0.0.1:1080; }
  server
  {
    listen       10000;
    server_name  :10000;
    index index.html index.htm index.php;
    root  /home/zhangy/www/metbee/trunk/src/web;
    #limit_conn   crawler  20;    
    location ~ .*.(php|php5)?$
    {      
         proxy_pass http://127.0.0.1:1081;
         break;
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
#     location /main {
#         proxy_pass http://fast_test;
#         break;
#     }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }
    location ~ .*.(js|css)?$
    {
      expires      1h;
    }    
    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /var/log/metbee.log  access;
      }
  server
  {
    listen       80;
    server_name  :80;
    index index.html index.htm blog/index.php;
    root  /home/zhangy/www;
     location /test {
         proxy_pass http://localhost:1080;
         break;
     }
#   location ~ .*.(php|php5|html)?$
# location ~ .*
#    {   
if (!-e $request_filename){
	rewrite ^/tag/(.*) /blog/index.php?tag=$1 last;
	rewrite ^/page/(d+)$  /blog/index.php?paged=$1 last;
	rewrite ^/(.*)/(d+).html /blog/index.php?p=$2 last;
	rewrite ^/category/(.*) /blog/index.php?category_name=$1 last;
#	rewrite ^/date/([0-9]{4,4})/([0-9]{1,2})?$ /blog/index.php?year=$1&monthnum=$2&page=$3 last;
#	rewrite ^/date/([0-9]{4,2})?$ /blog/index.php?m=$1$2 last;
    rewrite ^/newpage(d+)$  /blog/index.php?page_id=$1 last;
    rewrite ^/feed$  /blog/index.php?feed=rss2 last;
    rewrite ^/comment/feed$  /blog/index.php?feed=comment-rss2 last;
	rewrite http://blog.51yip.com$ http://blog.51yip.com/blog/index.php redirect;
}
location ~ .*.(php|php5)?$
   {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';
    access_log  /var/log/wwwlogs.log  wwwlogs;
  }
  server
  {
    listen       10001;
    server_name  :10001;
    index index.html index.htm index.php;
    root  /mnt/song/fastfds2/data;
    location ~ .*.(php|php5)?$
    {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }
    log_format  imagelogs  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';
    access_log  /var/log/imagelogs.log  imagelogs;
  }
  server
  {
    listen  11211;
    server_name :11211;
    location / {
    stub_status on;
    access_log   off;
    }
  }
}
2,fastcgi.conf cd /usr/local/nginx/conf nano /usr/local/nginx/conf/fastcgi.conf fastcgi_param? GATEWAY_INTERFACE? CGI/1.1; fastcgi_param? SERVER_SOFTWARE??? nginx; 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_FILENAME??? $document_root$fastcgi_script_name; 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? 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; 3,优化linux内核参数 nano /etc/sysctl.conf 在末尾加上下面的东东 net.ipv4.tcp_max_syn_backlog = 65536 net.core.wmem_default = 8388608 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 #net.ipv4.tcp_fin_timeout = 30 4,启动nginx ulimit -SHn 65535 5,查看启动 [zhangy@BlackGhost www]$ ps -e|grep nginx 五,开机启动 nano /etc/rc.local ulimit -SHn 65535 
 nginx fastcgi (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  

