nginx+fastcgi单机配置

 

拓扑图
 
 

 
    nginx主备配置
  1. [root@save ~]# yum -y install gcc gcc-c++ autoconf automake
    1. 安装编译工具,系统安装时选择develepment组件的话,这一步,只是gcc 和gcc-c++及其的8个依赖包进行update
  2. [root@save ~]# yum -y install zlib zlib-devel openssl opessl-devel pcre pcre-devel
    1. 安装nginx需要的模块和扩展库,只有pcre pcre-devel进行安装,其他进行升级
  3. [root@save ~]# yum -y install libxml2 libxml2-devel libjpeg libgpeg-devel libpng libpng-devel freeetype freetype-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel
    1. 安装php需要的模块和扩展库,其中,freetype-devel glib2-devel libjpeg-devel libpng-devel需进行安装,其他进行升级
  4. [root@save ~]# cd /usr/local/src/
  5. [root@save src]# wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.41.tar.gz
  6. [root@save mysql-5.1.41]# ./configure --prefix=/usr/local/webserver/mysql/ \
  7. > --enable-assembler \
    > --with-extra-charsets=complex \
    > --enable-thread-safe-client \
    > --with-big-tables \
    > --with-readline \
    > --with-ssl \
    > --with-embedded-server \
    > --enable-local-infile \
    > --with-plugins=innobase
  8. make && make install
  9. [root@save mysql-5.1.41]# useradd mysql
  10. [root@save mysql-5.1.41]# chown -R mysql:mysql /usr/local/webserver/mysql/
  11. [root@save mysql-5.1.41]# chmod +w /usr/local/webserver/mysql/
  12. [root@save src]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
  13. wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
  14. [root@save src]# wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
  15. wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
    1. 11-14下载I编译PHP(FASTCGI需要的库)
  16. 编译这些包:
  17. tar zxvf libiconv-1.13.1.tar.gz
  18. cd libiconv-1.13.1/
    ./configure --prefix=/usr/local
    make
    make install
     
  19. tar zxvf libmcrypt-2.5.8.tar.gz
  20. cd libmcrypt-2.5.8/
    ./configure
    make
    make install
    /sbin/ldconfig
    cd libltdl/
    ./configure --enable-ltdl-install
    make
    make install
     
  21. tar zxvf mhash-0.9.9.9.tar.gz
  22. cd mhash-0.9.9.9/
    ./configure
    make
    make install
  23. [root@save lib]# for i in `ls libmhash.*`;do ln -s /usr/local/lib/$i /usr/lib/$i;done
  24. [root@save lib]# for i in `ls libmcrypt.*`;do ln -s /usr/local/lib/$i /usr/lib/$i;done
    [root@save lib]# ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
    做库链接
  25. [root@save software]# wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
  26. [root@save software]# wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
  27. [root@save software]# tar zxvf php-5.2.14.tar.gz
  28. [root@save software]# gzip -cd php-5.2.14-fpm-0.5.14.diff.gz |patch -d php-5.2.14 -p1
  29. cd php-5.2.14/
  30. ./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
    make ZEND_EXTRA_LIBS='-liconv'
    make install
    cp php.ini-dist /usr/local/webserver/php/etc/php.ini
    1. 注:可能5.2.14版本php要求/usr/local/webserver/mysql/lib/mysql/libmysqlclient.so.16
    我用mysql-5.0.86的libmysqlclient版本是libmysqlclient.so.15,导致./configure 时,显示/usr/bin/ld libmysqlclient不兼容(incompatible)导致错误,无法进行make。我将mysql-5.1.41下的lib目录全部拷贝过来,替代原lib目录,重新./configure,正常
  31. 编译安装PHP5扩展模块
  32. tar zxvf memcache-2.2.5.tgz
    cd memcache-2.2.5/
    /usr/local/webserver/php/bin/phpize
    ./configure --with-php-config=/usr/local/webserver/php/bin/php-config
    make
    make install
    cd ../
     
    tar jxvf eaccelerator-0.9.6.1.tar.bz2
    cd eaccelerator-0.9.6.1/
    /usr/local/webserver/php/bin/phpize
    ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
    make
    make install
    cd ../
     
    tar zxvf PDO_MYSQL-1.0.2.tgz
    cd PDO_MYSQL-1.0.2/
    /usr/local/webserver/php/bin/phpize
    ./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
    make
    make install
    cd ../
     
    tar zxvf ImageMagick.tar.gz
    cd ImageMagick-6.5.1-2/
    ./configure
    make
    make install
    cd ../
    注:这个时间很长
     
    tar zxvf imagick-2.3.0.tgz
    cd imagick-2.3.0/
    /usr/local/webserver/php/bin/phpize
    ./configure --with-php-config=/usr/local/webserver/php/bin/php-config
    make
    make install
    cd ../
  33. 更改php.ini配置文件
  34. 查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
    修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
    并在此行后增加以下几行,然后保存:
    extension = "memcache.so"
    extension = "pdo_mysql.so"
    extension = "imagick.so"
    再查找output_buffering = Off
    修改为output_buffering = On
    再查找; cgi.fix_pathinfo=0
    修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞。
  35. 配置eAccelerator加速PHP:
  36. mkdir -p /usr/local/webserver/eaccelerator_cache
    vi /usr/local/webserver/php/etc/php.ini
    按shift+g键跳到配置文件的最末尾,加上以下配置信息:
    引用
    [eaccelerator]
    zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
    eaccelerator.shm_size="64"
    eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
    eaccelerator.enable="1"
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.debug="0"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="3600"
    eaccelerator.shm_prune_period="3600"
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="9"
  37. 创建虚拟主机目录
  38. [root@save etc]# mkdir -p /data0/htdocs/blog
    [root@save etc]# mkdir -p /data0/htdocs/www
    [root@save etc]# chmod +w /data0/htdocs/blog/
    [root@save etc]# chmod +w /data0/htdocs/www/
    [root@save etc]# chown -R www:www /data0/htdocs/www/
    [root@save etc]# chown -R www:www /data0/htdocs/blog/
  39. 修改php-fpm配置文件
  40. 文件:vi /usr/local/webserver/php/etc/php-fpm.conf
    取消注释:<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
    取消注释:<value name="display_errors">0</value>
    1. <value name="user">www</value>
    2. <value name="group">www</value>
    3. <value name="max_children">64</value>
    4. <value name="rlimit_files">65535</value>
    5. <value name="max_requests">1024</value>
  41. 安装Nginx 0.8.46
  42. 1、安装Nginx所需的pcre库:
    tar zxvf pcre-8.10.tar.gz
    cd pcre-8.10/
    ./configure
    make && make install
    cd ../
    2、安装Nginx
    tar zxvf nginx-0.8.46.tar.gz
    cd nginx-0.8.46/
    ./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
    make && make install
    cd ../
    3、创建Nginx日志目录
    mkdir -p /data1/logs
    chmod +w /data1/logs
    chown -R www:www /data1/logs
  43. 修改配置文件vi /usr/local/webserver/nginx/conf/nginx.conf
  44. user www www;
    worker_processes 8;
    error_log /data0/logs/nginx_error.log crit;
    pid /usr/local/webserver/nginx/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;
    server
    {
    listen 80;
    server_name blog.bears.com;
    index index.html index.htm index.php;
    root /data0/htdocs/blog;
    #limit_conn crawler 20;
    location ~ .*\.(php|php5)?$
    {        
    #fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf;
    }
    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 /data0/logs/access.log access;
    }
    server
    {
    listen 80;
    server_name www.bears.com;
    index index.html index.htm index.php;
    root /data0/htdocs/www;
    location ~ .*\.php$
    {
    #fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.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 /data0/logs/wwwlogs.log wwwlogs;
    }
    server
    {
    listen 80;
    server_name status.blog.s135.com;
    location / {
    stub_status on;
    access_log off;
    }
                }
    }
  45. 编辑fcgi.conf文件:[root@save conf]# vim fcgi.conf
  46.  
    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;
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

你可能感兴趣的:(web服务)