nginx安装与配置
1,安装MySQL 5.1.22(简单免去)
2,编译安装PHP(FastCGI模式)
tar zxvf php-5.2.5.tar.gz
cd php-5.2.5/
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir \
--enable-xml --disable-debug --disable-rpath --enable-discard-path --enable-fastcgi \
--enable-force-cgi-redirect --enable-mbstring
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini
3,编译安装PHP5扩展模块
tar zxvf memcache-2.2.1.tgz
cd memcache-2.2.1/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd php-5.2.5/ext/gd/
/usr/local/php/bin/phpize
./configure --with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir --with-php-config=/usr/local/php/bin/php-config
make
make install
4,修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存:
extension = "memcache.so"
extension = "gd.so"
5,创建www用户和组,以及其使用的目录:
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
mkdir -p /data0/vshare/htdocs
chmod +w /data0/vshare/htdocs
chown -R www:www /data0/vshare/htdocs
6,安装lighttpd中附带的spawn-fcgi,用来启动php-cgi
注:压缩包中的spawn-fcgi程序为已经编译成二进制的版本。
cp spawn-fcgi /usr/local/php/bin
chmod +x /usr/local/php/bin/spawn-fcgi
7,启动php-cgi进程,监听127.0.0.1的10080端口,进程数为64(如果服务器内存小于3GB,可以只开启25个进程),用户为www:
/usr/local/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -
f /usr/local/php/bin/php-cgi
8,安装Nginx 0.5.33
安装Nginx所需的pcre库:
tar zxvf pcre-7.2.tar.gz
cd pcre-7.2/
./configure
make && make install
9,安装Nginx
tar zxvf nginx-0.5.33.tar.gz
cd nginx-0.5.33/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module
make && make install
10,创建Nginx日志目录
mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -R www:www /var/log/nginx
11,创建Nginx配置文件
在/usr/local/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/nginx/conf/nginx.conf
vi /usr/local/nginx/conf/nginx.conf,配置文件如下:
user www www;
worker_processes 10;
error_log /data1/logs/nginx_error.log crit;
#pid logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include conf/mime.types;
default_type application/octet-stream;
charset gb2312;
server_names_hash_bucket_size 128;
#sendfile on;
#tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/html application/xml;
server
{
listen 80;
server_name blog.s135.com;
index index.html index.htm index.php;
root /data0/vshare/htdocs;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location ~ .*\.php?$
{
include conf/fcgi.conf;
fastcgi_pass 127.0.0.1:10080;
fastcgi_index index.php;
}
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 /data1/logs/access.log access;
}
server
{
listen 80;
server_name status.blog.s135.com;
location / {
stub_status on;
access_log off;
}
}
}
在/usr/local/nginx/conf/目录中创建fcgi.conf文件:
vi /usr/local/nginx/conf/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;
日志滚动脚本如下:
#!/bin/bash
log_dir="/var/log/nginx/"
date_file=`date +%Y%m%d%H`
/bin/mkdir -p ${log_dir} > /dev/null 2>&1
/bin/mv ${log_dir}/access.log ${log_dir}/${date_file}
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
原文链接:
http://blog.s135.com/read.php/314.htm