首页 → 服务器应用
背景:
阅读新闻
LNAMP第二版(Nginx 1.2.0+Apache 2.4.2+PHP 5.4)
[日期:2012-05-09]
来源:Linux社区
作者:kerry
[字体:]
#============= Install Nginx ===================#
cd /opt
tar -zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-pcre=/opt/pcre-8.30 --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-google_perftools_module
make;make install
cd ../
#添加nginx启动脚本
cat >> /etc/init.d/nginx <<EOF #! /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 EOF
#添加nginx配置文件
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
cat >> /usr/local/nginx/conf/nginx.conf <<EOF user www www; worker_processes 8; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; #使用Tcmalloc优化nginx性能 google_perftools_profiles /var/tmp/tcmalloc; #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服务器,利用它的反向代理功能提供负载均衡支持 http { #设定mime类型 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 30m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; server_tokens off; client_body_buffer_size 512k; proxy_connect_timeout 5; proxy_send_timeout 60; proxy_read_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; # 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.1; 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; #定义访问日志的写入格式 log_format wwwlog '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; log_format bbslog '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; ###禁止通过ip访问站点 server{ server_name _; return 404; } server { listen 80; server_name ; index index.html index.htm index.php;#设定访问的默认首页地址 root /data/www/linuxidc;#设定网站的资源存放路径 #limit_conn crawler 20; if (-d $request_filename) { rewrite ^/(.*)([^/])$ $host/$1$2/ permanent; } #所有jsp的页面均交由tomcat处理 location ~ \.(php)?$ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass :81;#转向tomcat处理 } location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ #设定访问静态文件直接读取不经过apache { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } access_log /data/logs/linuxidc/linuxidc_nginx.log wwwlog;#设定访问日志的存放路径 } server { listen 80; server_name ; index index.html index.htm index.php;#设定访问的默认首页地址 root /data/www/king;#设定网站的资源存放路径 #limit_conn crawler 20; if (-d $request_filename) { rewrite ^/(.*)([^/])$ $host/$1$2/ permanent; } #所有jsp的页面均交由tomcat处理 location ~ \.(php)?$ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass :81;#转向tomcat处理 } location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ #设定访问静态文件直接读取不经过apache { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } access_log /data/logs/king/king_nginx.log bbslog;#设定访问日志的存放路径 } server { listen 80; server_name status.; location / { stub_status on; access_log off; } } } EOF
#将nginx添加到启动服务中
chmod 700 /etc/init.d/nginx
/etc/init.d/nginx start
/sbin/chkconfig --add nginx
/sbin/chkconfig --level 2345 nginx on
红帽企业集群和存储管理之DRBD+Heartbeat+NFS实现详解
/var/spool/clientmqueue目录~清理
相关资讯
LNAMP
本文评论
查看全部评论 (0)
评论声明
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款
最新资讯