Article 5: Use eclipse in Linux for nginx module development

Source: Internet
Author: User
Article content 1. Download nginx code 2. Create a Module Directory and code 3. Create a MAKEFILE file 4. Create a project under eclipse 5. modify the configuration parameters under eclipse 6. Test
1. This article assumes that you have successfully installed nginx. Of course, it does not matter if you have not installed nginx.

2. For details, refer to Baidu Library. 1. download the latest nginx code$ Wget http://www.nginx.org/download/nginx-1.2.3.tar.gz extract $ tar zxvf nginx-1.2.3.tar.gz into directory $ CD nginx-1.2.3 2. Create a Module Directory and codeNote: 1) To be able to debug the module, we need to put the module source code into the nginx root directory nginx-1.2.3 directory. 2) in order to clear the directory structure, my directory structure is as follows nginx-1.2.3/add_module_src/Module source code Step 1: 1. check whether the current directory is the Nginx-1.2.3 directory PWD 2. create the add_module_src directory $ mkdir add_module_src 3. go to the add_module_src directory and create the ngx_hello_world_module directory $ CD add_module_src $ mkdir ngx_hello_world_module 4. go to ngx_hello_world_module and create two files, config and ngx_http_hello_world.c. Command 1) $ CD ngx_hello_world_module 2) $ Vim config3) $ Vim ngx_http_hello_world.c where the content in config is:
 
The content in ngx_http_hello_world.c is
 
3. Create a MAKEFILE fileNote: to convert the directory to the Nginx-1.2.3 directory, Step 1: 1. Generate the MAKEFILE file using the configure script provided by nginx. Written in http://blog.csdn.net/yankai0219/article/details/8001210.
./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
Note: 1) -- add-module add module, followed by the module source code. 2) -- With-Debug specifies the debug compilation. 4. Create a project in eclipse,1) Based on the written sources 5. modify the configuration parameters in eclipse1) modify the build option. It mainly modifies the value of build. In my eclipse version, modify the method as follows: 1. Select the Nginx-1.2.3 project in project explorer, right-click to select project properties. Find C/C ++ build on the right. 2. C/C ++ build ---- Change build to empty. 3. Configure the running parameters. Open the run configuration dialog box. 1) set the parameters in run --- run configuration on the menu bar. In C/C ++ application, select objs/nginx (if not, make it once first ). Add arguments -C/home/hpnl/nginx_source/nginx-1.2.3/CONF/nginx. confSpecifies the runtime configuration file. Note: The added conf file is in the nginx source code directory. 2) modify the content of the conf file (complete file) in bold to the modified part.
# 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 x.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 Fig: 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 5 m;

# Ssl_protocols SSLv2 SSLv3 tlsv1;
# Ssl_ciphers high :! Anull :! MD5;
# Ssl_prefer_server_ciphers on;

# Location /{
# Root HTML;
# Index index.html index.htm;
#}
#}

}

6. TestClick Run and enter $ curl http: // localhost/hello in the command line to output Hello, world so far, you can set breakpoints for the modules you have added and debug them.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.