文章内容
1.下载Nginx代码
2.建立模块目录和代码
3.创建Makefile文件
4.Eclipse下创建工程
5.修改Eclipse下配置参数
6.测试
|
1.本文假设你已成功安装Nginx,当然如果你没有安装,也没有关系。
2.本文内容参考百度文库
http://wenku.baidu.com/view/253c98d5b14e852458fb57f5.html,可惜下载需要5分让人郁闷,而且有些地方也不一样。
1.下载Nginx最新代码
解压缩 $tar zxvf nginx-1.2.3.tar.gz
进入目录 $cd nginx-1.2.3
2.建立模块目录与代码
注意:1)为了能够调试module,我们需要将module的源码放入nginx的根目录nginx-1.2.3目录中。
2)为了以后目录结构的清晰,我的目录结构如下nginx-1.2.3/add_module_src/module 源代码
步骤一:
1.检查当前目录是否为Nginx-1.2.3目录 pwd
2.创建add_module_src 目录 $ mkdir add_module_src
3.进入add_module_src目录,创建ngx_hello_world_module目录 $cd add_module_src $mkdir ngx_hello_world_module
4.进入ngx_hello_world_module,新建两个文档config和ngx_http_hello_world.c两个文件。
命令1) $cd ngx_hello_world_module 2)$vim config3)$vim ngx_http_hello_world.c
其中config中内容为:
ngx_http_hello_world.c中内容为
3.创建Makefile文件
注意:要将目录转换到Nginx-1.2.3目录下
步骤一:
1.利用nginx提供的configure脚本生成Makefile文件。
./configure--user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=../add_module_src /ngx_hello_world_module --with-debug
|
注意:1)--add-module添加模块,后面即该模块源码的位置。
2)--with-debug指定debug编译。
4.在Eclipse中建工程,
1)根据中所写
http://blog.csdn.net/yankai0219/article/details/8000034中4.导入已经存在的项目中的方法,导入Nginx 源码
5.修改Eclipse下配置参数
1)修改build选项。主要是修改Build的取值。
在我的Eclipse版本中,修改方法如下:
1.在Project Explorer中选中Nginx-1.2.3项目,点击右键选中Project Properties。在右侧找到C/C++ Build。
2.C/C++ Build ----Behavior 将Build改为空即可。如下图所示
3.配置运行参数,打开Run Configuration对话框
1)在菜单栏Run---Run Configuration 中设置。C/C++ Application中选择objs/nginx(如果没有,先make一次)。Arguments添加
-c /home/hpnl/nginx_source/nginx-1.2.3/conf/nginx.conf指定运行时配置文件。注意:所添加的conf文件是在nginx源代码目录中的。
2)修改该conf的内容(完整文件)加粗字体为改动部分。
#user nobody; worker_processes 1; daemon off; #daemon must be set as off #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /hello{ hello_world; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } |
6.测试
点击运行, 在命令行中输入$ curl
http://localhost/hello 输出hello,world
到此为止,就可以对自己添加的模块设置断点,进行调试了。