分页: 2/2 第一页 上页 1 2 最后页 [ 显示模式: 摘要 | 列表 ]
May 16
这两天搭建了一组Apache服务器,每台服务器4G内存,采用的是prefork模式,一开始设置的连接数太少了,需要较长的时间去响应用户的请求,后来修改了一下Apache 2.0.59的配置文件httpd.conf:
引用
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves

StartServers 10
MinSpareServers 10
MaxSpareServers 15
ServerLimit 2000
MaxClients 2000
MaxRequestsPerChild 10000

查看httpd进程数(即prefork模式下Apache能够处理的并发请求数):
Linux命令:
ps -ef | grep httpd | wc -l
返回结果示例:
1388
表示Apache能够处理1388个并发请求,这个值Apache可根据负载情况自动调整,我这组服务器中每台的峰值曾达到过2002。
查看Apache的并发请求数及其TCP连接状态:
Linux命令:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
(这条语句是从新浪互动社区事业部技术总监王老大那儿获得的,非常不错)
返回结果示例:
LAST_ACK 5
SYN_RECV 30
ESTABLISHED 1597
FIN_WAIT1 51
FIN_WAIT2 504
TIME_WAIT 1057
其中的SYN_RECV表示正在等待处理的请求数;ESTABLISHED表示正常数据传输状态;TIME_WAIT表示处理完毕,等待超时结束的请求数。
关于TCP状态的变迁,可以从下图形象地看出:
点击在新窗口中浏览此图片
状态:描述
CLOSED:无连接是活动的或正在进行
LISTEN:服务器在等待进入呼叫
SYN_RECV:一个连接请求已经到达,等待确认
SYN_SENT:应用已经开始,打开一个连接
ESTABLISHED:正常数据传输状态
FIN_WAIT1:应用说它已经完成
FIN_WAIT2:另一边已同意释放
ITMED_WAIT:等待所有分组死掉
CLOSING:两边同时尝试关闭
TIME_WAIT:另一边已初始化一个释放
LAST_ACK:等待所有分组死掉
Tags:
May 16
nginx添加参数可以允许打开目录浏览功能,详见http://bbs.linuxtone.org/viewthread.php?tid=2563&rpid=9073&ordertype=0&page=1#pid9073或者
官方的 http://wiki.nginx.org/NginxHttpAutoindexModule

这是说的是支持目录浏览的第三方插件fancyindex
本次试验用的nginx-0.8.15
第三方插件下载地址
http://download.snake.de/dist/ngx-fancyindex-0.2.1.tar.bz2

[root@test src]# tar zxvf nginx-0.8.15.tar.gz
[root@test src]# tar jxvf ngx-fancyindex-0.2.1.tar.bz2
[root@test src]# cd nginx-0.8.15
[root@test nginx-0.8.15]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx-fancyindex-0.2.1

然后根据自己的目录浏览要求配置 nginx.conf ,以下为我的主机配置

引用
server {
listen 80;
server_name 192.168.11.12;
location / {
fancyindex on;#开启 fancy indexes
fancyindex_exact_size off;#显示文件大小。
# autoindex on;
#autoindex_localtime on;
#autoindex_exact_size off; 注释这三项是不装插件开启目录浏览功能。
root /data ;
}
}

[root@test nginx]# ./sbin/nginx -t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@test nginx]# ./sbin/nginx

完成配置。
这里只是用到了插件fancyindex的2个参数,还有 fancyindex_localtimefancyindex_headerfancyindex_footer = 大家研究一下。。可以看一下这里 http://wiki.nginx.org/NginxNgxFancyIndex 。
不知道 安装这个插件与没有安装过插件开启,在效率上是否有不同。。。
下面截图是 安装过插件 和nginx 开启目录浏览 截图。
点击在新窗口中浏览此图片
点击在新窗口中浏览此图片
点击在新窗口中浏览此图片
Tags: ,
May 16
LVS:略
nginx proxy 配置:
引用

location / {
root /data/www/wwwroot/bbs.linuxtone.com;
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
proxy_pass http://bbs.linuxtone.org;
}

源nginx配置:
安装
HttpRealIpModule模块:
http://wiki.nginx.org/NginxChsHttpRealIpModule
--with-http_realip_module
编译方法:
引用

./configure --user=daemon --group=daemon --prefix=/usr/local/nginx/
--with-http_stub_status_module --with-http_ssl_module
--with-http_sub_module --with-md5=/usr/lib --with-sha1=/usr/lib
--with-http_gzip_static_module --with-http_realip_module

虚拟主机增加配置:
set_real_ip_from nginx_proxy_ip/24;
set_real_ip_from nginx_proxy_ip;
real_ip_header X-Real-IP;

EXP:
set_real_ip_from 192.168.1.0/24;
set_real_ip_from 192.168.1.6;
real_ip_header X-Real-IP;

查看二台nginx的日志就能取到真实IP了
Tags: , ,
May 16
有时候为了伪装自己的真实服务器环境.
不想让对方知道自己的webserver真实环境,就不得不修改我们的webserer软件了!
今天看了一下baidu.com的webserver感觉像是nginx修改的.
C:\curl-7.18.0\curl.exe -I www.baidu.com
HTTP/1.1 200 OK
Date: Tue, 11 Mar 2008 05:00:39 GMT
Server: BWS/1.0
Content-Length: 3022
Content-Type: text/html
Cache-Control: private
Expires: Tue, 11 Mar 2008 05:00:39 GMT
Set-Cookie: BAIDUID=41BB2845D3E8BC1AEE99D4CECB90C50A:FG=1; expires=Tue, 11-
8 05:00:39 GMT; path=/; domain=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "

于是自己翻了一下nginx源码了,发现竟然很容修改就可以实现.
cd /usr/local/src/nginx-0.5.35/src/core/
[root@zyatt core]# cat nginx.h
/*
* Copyright (C) Igor Sysoev
*/

#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_


#define NGINX_VERSION "1.0"
#define NGINX_VER "LPKWS/" NGINX_VERSION

#define NGINX_VAR "LPKWS"
#define NGX_OLDPID_EXT ".oldbin"

#endif /* _NGINX_H_INCLUDED_ */

测试效果
C:\curl-7.18.0\curl.exe -I 211.100.11.122/info.php (此Nginx没有做优化,配置expires,gzip等,仅为测试)

HTTP/1.1 200 OK
Server: LPKWS/1.0
Date: Tue, 11 Mar 2008 04:53:02 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/5.2.4
要想更彻底点,把下面这几个文件也修改了
修改src/http/ngx_http_header_filter_module.c
static char ngx_http_server_string[]="Server: nginx" CRLF;
修改src/http/ngx_http_special_response.c
static u_char ngx_http_error_tail[]="<hr><center>nginx</center>" CRLF"</body>" CRLF"</html>" CRLF;
修改Nginx的FastCGI配置文件fastcgi.conf
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

要想真正的优化和安全考虑,还是应该好好读读源代码,踏踏实实做好细节工作!
Tags: ,
分页: 2/2 第一页 上页 1 2 最后页 [ 显示模式: 摘要 | 列表 ]