背景:
阅读新闻
CentOS 5.4下 Nginx+Apache搭建前后端web生产环境
[日期:2010-12-24] 来源:Linux社区 作者:Linux [字体:]
四.安装nginx
1.安装pcre库
cd /usr/local/src
tar -zxf pcre-8.01.tar.gz
cd pcre-8.01
./configure
make
make install
2.安装nginx
cd /usr/local/src
tar -zxf nginx-0.7.65.tar.gz
cd nginx-0.7.65
./configure –user=nobody –group=nobody –prefix=/usr/local/nginx –pid-path=/usr/local/nginx/logs/nginx.pid –error-log-path=/usr/local/nginx/logs/error.log –http-log-path=/usr/local/nginx/logs/access.log –http-client-body-temp-path=/tmp/nginx_client –http-proxy-temp-path=/tmp/nginx_proxy –http-fastcgi-temp-path=/tmp/nginx_fastcgi –with-http_stub_status_module
make
make install
2.1.添加init控制脚本
#! /bin/sh
ulimit -n 65535
# Description: Startup script for nginx
# chkconfig: 2345 55 25
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -QUIT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can’t reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
/etc/init.d/httpd start
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
/etc/init.d/httpd stop
;;
reload)
echo -n "Reloading $DESC configuration…"
do_reload
echo "."
/etc/init.d/httpd restart
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
sleep 1
do_start
echo "."
/etc/init.d/httpd restart
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0保存退出,给该文件赋予执行权限并设置开机启动
chmod u+x /etc/init.d/nginx
chkconfig –level 345 nginx on
2.2.修改nginx配置文件,位于:/usr/local/nginx/conf/目录
cd /usr/local/nginx/conf/
mv nginx.conf nginx.conf.bak
mkdir vhosts
vi nginx.conf
输入以下内容:
worker_processes 1;
worker_rlimit_nofile 65535;
events {
worker_connections 65535;
use epoll;
}
error_log /usr/local/nginx/logs/error.log info;
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
gzip on;
gzip_http_version 1.0;
gzip_min_length 1100;
gzip_comp_level 3;
gzip_buffers 4 32k;
gzip_types text/plain text/xml text/css application/x-Javascript application/xml application/xml+rss text/javascript application/atom+xml;
ignore_invalid_headers on;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
server_names_hash_max_size 2048;
server_names_hash_bucket_size 256;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
request_pool_size 32k;
output_buffers 4 64k;
postpone_output 1460;
open_file_cache max=1000 inactive=300s;
open_file_cache_valid 600s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
include "/usr/local/nginx/conf/vhosts/*.conf";
server {
listen 80;
server_name _;
access_log off;
location ~* .(ftpquota|htaccess|asp|aspx|jsp|asa|mdb)$ {
deny all;
}
location / {
client_max_body_size 100m;
client_body_buffer_size 128k;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_connect_timeout 30s;
proxy_pass :81/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}保存退出.
CentOS 5.5如何通过yum安装Zend Optimizer
相关资讯 CentOS
本文评论 查看全部评论 (0)
尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯