Posted by bianbian on 2008-03-13 10:21
本文Tags: debug, gcc, nginx, 编译
默认的nginx编译选项里居然是用debug模式(-g)的(debug模式会插入很多跟踪和ASSERT之类),编译以后一个nginx有好几兆。
去掉nginx的debug模式编译,编译以后只有375K(nginx-0.5.33, gcc4)。
在 auto/cc/gcc,最后几行有:
# debug
CFLAGS=”$CFLAGS -g”
注释掉或删掉这几行,重新编译即可。-g参数用法详见这篇blog:[原]Linux下的c/c++ GDB调试
Nginx uses debug mode (-g) in compiling by default, which result in several MB of it’s size.
After debug disabled, the file size of nginx reduced to 375K (nginx-0.5.33, gcc4).
open auto/cc/gcc, find this at last several lines:
# debug
CFLAGS=”$CFLAGS -g”
delete it, and recompile. More of -g: Linux c/c++ GDB debug
标签:
debug,
gcc,
nginx,
编译遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in C/C++, Linux, Technology | No Comments »
Posted by bianbian on 2007-10-16 02:17
本文Tags: bug, internal, nginx
文档上说,internal用来禁止用户直接通过地址访问。
syntax: internal
default: no
context: location
internal indicates that the matching location can be used only for so called “internal” requests.
For external requests it will return the error “Not found” (404).
Internal requests are the following:
1) requests redirected by the instruction error_page
2) subrequests created by the command include virtual of the “ngx_http_ssi_module” module
3) requests changed by the instruction rewrite of the “ngx_http_rewrite_module” module
An example to prevent clients fetching error pages directly:
- error_page 404 /404.html;
- location /404.html {
- internal;
- }
实际发现,rewrite的用internal修饰后就挂了。像下面这个配置,如果/realpath/设了internal,用/proxypath/访问就是404。
这个跟本意是违背的(本意只能通过/proxypath/访问,而隐藏/realpath/),应该是nginx的bug(我的版本0.5.32)
- location /proxypath/ {
- root /realpathroot;
- rewrite ^/proxypath/(.+)$ /realpath/$1? last;
- }
- location /realpath/ {
- internal;
- }
标签:
bug,
internal,
nginx遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in Linux, Technology | No Comments »
Posted by bianbian on 2007-09-16 12:24
本文Tags: nginx, slackware, 编译
configure就不说了,make的时候提示:
objs/src/event/ngx_event.o(.text+0xdbc): In function `ngx_event_init_conf’:src/event/ngx_event.c:1140: warning: warning: epoll_create is not implemented and will always fail
objs/src/event/modules/ngx_epoll_module.o(.text+0×1cc): In function `ngx_epoll_add_event’:src/event/modules/ngx_epoll_module.c:250: warning: warning: epoll_ctl is not implemented and will always fail
objs/src/event/modules/ngx_epoll_module.o(.text+0×416): In function `ngx_epoll_process_events’:src/event/modules/ngx_epoll_module.c:402: warning: warning: epoll_wait is not implemented and will always fail
epoll是高性能网络io,居然不被系统支持,我明明用的是2.6.17的内核。于是make menuconfig,到 General setup / Configure standard kernel features 发现’Enable event poll’ 是关闭的,于是启用。
然后重新编译内核:
make bzImage
make modules
make modules_install
cp System.map /boot/
cp arch/i386/boot/bzImage /boot/vmlinuz
lilo
reboot
话说,Slackware 12.0都出来几个月了,改天我要去装一下。^_^
标签:
nginx,
slackware,
编译遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in Linux, Technology | 1 Comment »
Posted by bianbian on 2007-04-06 09:49
本文Tags: nginx, worker_processes, 配置
搜索到原作者的话:
一般一个进程足够了,你可以把连接数设得很大。如果有SSL、gzip这些比较消耗CPU的工作,而且是多核CPU的话,可以设为和CPU的数量一样。或者要处理很多很多的小文件,而且文件总大小比内存大很多的时候,也可以把进程数增加,以充分利用IO带宽(主要似乎是IO操作有block)。
As a general rule you need the only worker with large number of
worker_connections, say 10,000 or 20,000.
However, if nginx does CPU-intensive work as SSL or gzipping and
you have 2 or more CPU, then you may set worker_processes to be equal
to CPU number.
Besides, if you serve many static files and the total size of the files
is bigger than memory, then you may increase worker_processes to
utilize a full disk bandwidth.
Igor Sysoev
经我实践配置,多cpu+gzip+N多小文件+文件总大小大大超过内存 的环境(BBS啦~),设置为cpu的两倍较好。(不过一个nginx是4.3M噢)
标签:
nginx,
worker_processes,
配置遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in Linux, Technology | 2 Comments »
Posted by bianbian on 2007-04-06 09:15
本文Tags: fastcgi, nginx
终于明白,俺的Linux基本功果然很烂。。。。
FastCGI echo
Request number 1, Process ID: 7422
No data from standard input.
Request environment:
FCGI_ROLE=RESPONDER
GATEWAY_INTERFACE=CGI/1.1
QUERY_STRING=
REQUEST_METHOD=GET
CONTENT_TYPE=
CONTENT_LENGTH=
SCRIPT_NAME=/echo.net
REQUEST_URI=/echo.net
DOCUMENT_URI=/echo.net
DOCUMENT_ROOT=/home/nginx/html
SERVER_PROTOCOL=HTTP/1.1
…..
标签:
fastcgi,
nginx遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in Linux, Technology | No Comments »
Posted by bianbian on 2007-04-05 04:40
本文Tags: nginx, X-Accel-Redirect, 控制
有时你可能需要实现控制下载:即将下载文件的请求转发到某脚本, 然后由这脚本决定怎么做:发送这个文件给用户,出现决绝访问页,或着其他的事。在lighttpd服务器里可以通过从脚本传回X-Sendfile头实现;而Nginx是通过使用X-Accel-Redirect头实现的。在这篇文章里我会尽量简捷地描述在php和rails里如何使用这一特性。
假设你使用Apache运行PHP或Rails产生动态内容,而用Nginx作为前台反向代理(bianbian注:反向代理又称为服务器加速(Server accelerate),原理是将用户的请求转发到目标服务器,然后将结果转发给用户。好处有很多:保护目标服务器安全、负载均衡容易实现、有点类似防火墙;坏处我认为就是要传递用户的IP的时候多了些步骤)。你就达到了两个目标:
- 因为Nginx服务器会改善所有对动态内容的缓慢请求,能节省服务器的资源(细节正在
这里). (bianbian注:凭我对Nginx的理解,这个就是Nginx会缓存客户端的请求,等全部发送完毕了才一起转发给后台脚本,比如在上载文件的时候。好处是减少后台脚本等待的时间,确实对性能有一定改善;坏处就是在脚本里时时显示上载进度的功能是不可能实现了[当然,以后Nginx如果自己开放这个进度API也是可能的,不过也不是脚本级的,好在显示进度的功能不常用])
- 你能对静态文件的下载做出控制.(bianbian注:后面的一大段都是说这个啦!)
在这里,假设网站位于 /var/www 目录,而一些静态文件(类似电影、歌曲、或其他)位于 /var/www/files 目录。Apache监听8080端口。
首先,让我们看一看nginx配置:
Read the rest of this entry »
标签:
nginx,
X-Accel-Redirect,
控制遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in Linux, Technology | 4 Comments »
Posted by bianbian on 2007-04-05 07:11
本文Tags: nginx, 反向代理
Nginx [engine x] is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server written by Igor Sysoev. It has been running on many heavily loaded Russian sites for more than two years.
俄罗斯人写的,我总觉得俄罗斯都是高手。。。。再仔细看了一下(所有能看懂的文档),基于事件的,对小文件的读写性能很好,也更适合做反向代理(nginx 》Squid 》Apache),更适合BBS的情况。所以决定装这个。
http://sysoev.ru/nginx/download.html
俄语,不要紧,最上面那个就是最新的。
下载解压安装:
tar zxf nginx-x.x.x.tar.gz
cd nginx-x.x.x
./configure --prefix=/opt/nginx --with-http_realip_module
make
make install
这样配置文件在/opt/nginx/conf/nginx.conf
cd /opt/nginx
vim conf/nginx.conf
配置文件格式有点像lighttpd,其实你熟悉JavaScript或JSON的话应该很容易看懂。
我修改的内容:
反向代理:
location / {
proxy_pass http://localhost:8000/;
proxy_set_header X-Real-IP $remote_addr;
}
#禁止下载所有.开头的文件名,如 .DIR
location ~ /\..+ {
deny all;
}
标签:
nginx,
反向代理遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in Linux, Technology | 2 Comments »