接上文。 一、安装pcre:cd /usr/local/src wget http://downloads./project/pcre/pcre/8.34/pcre-8.34.tar.gz 二、下载proxy_cache插件cd /usr/local/src wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
三、安装tengineyum install openssl openssl-devel -y
/usr/local/nginx/sbin/nginx #启动nginx
chown nobody.nobody -R /usr/local/nginx/html
chmod 700 -R /usr/local/nginx/html
如果编译的问题的话,看看是不是下面的原因: ./configure: error: the HTTP SSL module requires OpenSSL library 原因:安装http_ssl_module模块需要openssl library 解决:yum install openssl-devel ./configure: error: the HTTP rewrite module requires the PCRE library. 原因:安装http_rewrite_module模块需要先安装PCRE开发包 解决:yum install pcre-devel
注意: --with-pcre=/usr/local/src/pcre-8.21指向的是源码包解压的路径,而不是安装的路径,否则会报错。 --add-module=/usr/local/src/ngx_cache_purge-2.1 是指加载缓存的插件模块 四、设置Tengine开机启动vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容 #!/bin/bash # Tengine Startup script# processname: nginx # chkconfig: - 85 15 # description: nginx is a World Wide Web server. It is used to serve # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "tengine already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL 保存退出 chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限 chkconfig --level 012345 nginx on #设置开机启动 /etc/rc.d/init.d/nginx restart 四、配置Tengine mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak 编辑主配置文件: vi /usr/local/nginx/conf/nginx.conf 内容如下: user www www; worker_processes 4; # 工作进程数,为CPU的核心数或者两倍 error_log logs/error.log crit; # debug|info|notice|warn|error|crit pid logs/nginx.pid; 编辑代理配置文件: cd /usr/local/nginx/conf/ mkdir vhost vi /usr/local/nginx/conf/proxy.conf 内容如下: #注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区 编辑主机配置文件: vi /usr/local/nginx/conf/mysvrhost.conf 内容如下: upstream cn100 { ip_hash; #会话保持 server 127.0.0.1:8080 max_fails=1 fail_timeout=60s; server 127.0.0.1:9080 max_fails=1 fail_timeout=60s; } 编辑压缩配置文件: vi /usr/local/nginx/conf/gzip.conf 内容如下: #网页GZIP压缩设置 #2012.4.2 #可通过http://tool.chinaz.com/Gzips/检测压缩情况 # #启动预压缩功能,对所有类型的文件都有效 #gzip_static on; #开启nginx_static后,对于任何文件都会先查找是否有对应的gz文件 #找不到预压缩文件,进行动态压缩 gzip on; gzip_min_length 1k; #设置最小的压缩值,单位为bytes.超过设置的min_length的值会进行压缩,小于的不压缩. gzip_comp_level 3; #压缩等级设置,1-9,1是最小压缩,速度也是最快的;9刚好相反,最大的压缩,速度是最慢的,消耗的CPU资源也多 gzip_buffers 16 64k; #设置系统的缓存大小,以存储GZIP压缩结果的数据流,它可以避免nginx频烦向系统申请压缩空间大小 gzip_types text/plain application/x-javascript text/css text/javascript; #关于gzip_types,如果你想让图片也开启gzip压缩,那么用以下这段吧: #gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png; #gzip公共配置 gzip_http_version 1.1; #识别http的协议版本(1.0/1.1) gzip_proxied any; #设置使用代理时是否进行压缩,默认是off的 gzip_vary on; #和http头有关系,加个vary头,代理判断是否需要压缩 gzip_disable "MSIE [1-6]."; #禁用IE6的gzip压缩 编辑配置文件: vi /usr/local/nginx/conf/vhost/cn100.conf 内容如下: server { #配置发布目录为/usr/local/tomcat1/webapps/ROOT location / #对不同的HTTP状态码设置不同的缓存时间 proxy_set_header Host $host; proxy_pass_header Set-Cookie; #对用户传输Set-Cookie的http头,不然无法支持一些包含cookie的应用,比如我的typecho #过期时间3天 #用于清除缓存,假设一个URL为http://192.168.8.42/test.txt,通过访问http://192.168.8.42/purge/test.txt就可以清除该URL的缓存。
# 查看nginx的并发连接数配置 #定义Nginx输出日志的路径 为Tengine配置一下系统的TCP设置,优化一下: vi /etc/sysctl.conf 内容如下: net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.tcp_sack = 1 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_rmem = 4096 87380 4194304 net.ipv4.tcp_wmem = 4096 16384 4194304 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.core.netdev_max_backlog = 262144 net.core.somaxconn = 262144 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 30 net.ipv4.ip_local_port_range = 1024 65000 #允许系统打开的端口范围 使配置立即生效 /sbin/sysctl -p 制作一个重启全部的脚本 vi /root/restartall #!/bin/sh # #重启memcached进程 service memcached restart #清空日志 rm -f /usr/local/tomcat1/logs/* rm -f /usr/local/tomcat2/logs/* /usr/local/tomcat2/bin/shutdown.sh /usr/local/tomcat1/bin/startup.sh /usr/local/tomcat2/bin/startup.sh #重启nginx
给运行权限 |
|