RHEL5.8上安装Nginx+php(FastCGI)+MySQL 构建高效Web服务器(3)

六,安装php加速器,xcache
1.编译安装xcache#cd /usr/src #tar xzvf xcache-2.0.0.tar.gz #cd xcache-2.0.0 #/usr/local/php/bin/phpize #./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config #make  #make install 

2.整合php跟xcache

#mkdir /etc/php.d #cp /usr/src/xcache-2.0.0/xcache.ini /etc/php.d/ #vim /etc/php.d/xcache.ini  将三行替换为以下行 zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so 

七,整合nginx跟php(FastCGI模式)
1. 编辑nginx主配置文件

vim /usr/local/nginx/conf/nginx.conf  内容如下,可以将原文替换为以下内容user  nginx; worker_processes  10;  error_log  logs/error.log crit;      pid        logs/nginx.pid;       events   use epoll;   worker_connections 51000;  http {     include       mime.types;     default_type  application/octet-stream;         client_header_buffer_size 32k;         large_client_header_buffers 4 32k;         client_max_body_size 10m;      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/ccs application/xml;         gzip_vary on;      server {         listen       80;         server_name  ;         index index.html index.htm index.php;         root /web/www;          location ~ .*\.(php|php5)?$         {                 fastcgi_pass    127.0.0.1:9000;                 fastcgi_index index.php;                 fastcgi_param HTTPS on;                 include fastcgi.conf;         }         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$         {                 expires 30d;         }         location ~ .*\.(js|css)?$         {                 expires         1h;         }                 access_log      logs/www.log;              }          server {                 listen       80;                 server_name  bbs.andy.com;                 index index.html index.htm index.php;                 root /web/bbs;                  location ~ .*\.(php|php5)?$                 {                 fastcgi_pass    127.0.0.1:9000;                 fastcgi_index index.php;                 fastcgi_param HTTPS on;                 include fastcgi.conf;                 } 
                             access_log      logs/bbs.log;         }                  ##下面的是查看nginx状态的访问地址   配置下面的之后在地址栏输入 status.andy.com         ##就可以看到并发连接数等等信息         server  {                         listen 80;                         server_name     status.andy.com;                         location / {                             stub_status on;                             access_log      off;                             }             } 

2.编辑/usr/local/nginx/conf/fastcgi.conf文件

#vim /usr/local/nginx/conf/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  HTTPS              $https if_not_empty;  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; 

3.建立网站目录及测试文件

#mkdir -pv /web/{www,bbs} #vim /web/www/index.php 内容如下  这个页面是测试php跟nginx <?php phpinfo(); ?>  #vim /web/bbs/index.php  内容如下 这个页面是测试php跟MySQL <?php $link=mysql_connect('localhost','root',''); if ($link)         echo ok; else         echo no; mysql_close($link); ?> 

4.重启服务

#service nginx restart #service php-fpm restart #service mysqld restart 

ok 到这里基本已经结束了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/8d5f19d5b4f564ab38403902c5a774b9.html