centos nginx 安装文档 0.8.x

1.获取基本的相关的开源程序:

 

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

 

2.推荐两个RPM包搜索网站

 

http://rpm.pbone.net/
http://www.rpmfind.net/

3.先通过命令  rpm -qa | grep libjpeg 类似的命令 去检查上面这些包是否存在,否则,安装会出现缺少库支持

   rpm -ivh (filename) 是安装RPM包的命令

 

4.获取nginx的源代码包

 

wget http://sysoev.ru/nginx/nginx-0.8.46.tar.gz

 

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz  (安装nginx需要的库支持)

 

5.创建www:www用户和组

groupadd www

useradd -g www www

 

将nginx 安装在/usr/local/webserver/ 下面

以后就将web程序放在/var/www/下面

 

@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

 

网上推荐的一份nginx.conf

 

 

mv /usr/local/webserver/nginx/conf/nginx.conf /usr/local/webserver/nginx/conf/nginx.conf.bak
vi /usr/local/webserver/nginx/conf/nginx.conf

 

 

 

user  www www;

worker_processes 8;

error_log  /data1/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  www.test.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  /data1/logs/access.log  access;
      }




}

 

 

 

 

@1设置用户最大打开文件数

ulimit -SHn 65535

@2启动nginx

/usr/local/webserver/nginx/sbin/nginx

 

 

 

 

 

 

 

 

 

 

 

 

 

@1开机自动启动

vi /etc/rc.local

ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx

@2修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:

/usr/local/webserver/nginx/sbin/nginx -t

每天定时切割Nginx日志的脚本

1.创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh

vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path="/usr/local/webserver/nginx/logs/"

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

 

2.设置crontab,每天凌晨00:00切割nginx访问日志

crontab -e

输入:00 00 * * * /bin/bash  /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

 

 

 

 

 

 

你可能感兴趣的:(nginx,PHP,css,centos,Access)