nginx主备配置
- [root@save ~]# yum -y install gcc gcc-c++ autoconf automake
- 安装编译工具,系统安装时选择develepment组件的话,这一步,只是gcc 和gcc-c++及其的8个依赖包进行update
- [root@save ~]# yum -y install zlib zlib-devel openssl opessl-devel pcre pcre-devel
- 安装nginx需要的模块和扩展库,只有pcre pcre-devel进行安装,其他进行升级
- [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
- 安装php需要的模块和扩展库,其中,freetype-devel glib2-devel libjpeg-devel libpng-devel需进行安装,其他进行升级
- [root@save ~]# cd /usr/local/src/
- [root@save src]# wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.41.tar.gz
- [root@save mysql-5.1.41]# ./configure --prefix=/usr/local/webserver/mysql/ \
> --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
- make && make install
- [root@save mysql-5.1.41]# useradd mysql
- [root@save mysql-5.1.41]# chown -R mysql:mysql /usr/local/webserver/mysql/
- [root@save mysql-5.1.41]# chmod +w /usr/local/webserver/mysql/
- [root@save src]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
- wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
- [root@save src]# wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
- wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
- 11-14下载I编译PHP(FASTCGI需要的库)
- 编译这些包:
- tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
- tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
- tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
- [root@save lib]# for i in `ls libmhash.*`;do ln -s /usr/local/lib/$i /usr/lib/$i;done
[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
做库链接
- [root@save software]# wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
- [root@save software]# wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
- [root@save software]# tar zxvf php-5.2.14.tar.gz
- [root@save software]# gzip -cd php-5.2.14-fpm-0.5.14.diff.gz |patch -d php-5.2.14 -p1
- cd php-5.2.14/
./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
- 注:可能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,正常
- 编译安装PHP5扩展模块
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 ../
- 更改php.ini配置文件
查找/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文件类型错误解析漏洞。
- 配置eAccelerator加速PHP:
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"
- 创建虚拟主机目录
[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/
- 修改php-fpm配置文件
文件: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>
- <value name="user">www</value>
- <value name="group">www</value>
- <value name="max_children">64</value>
- <value name="rlimit_files">65535</value>
- <value name="max_requests">1024</value>
- 安装Nginx 0.8.46
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
- 修改配置文件vi /usr/local/webserver/nginx/conf/nginx.conf
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;
}
}
}
- 编辑fcgi.conf文件:[root@save conf]# vim fcgi.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;