无法在 nginx 服务器中运行简单的 hello world 模块

无法在 nginx 服务器中运行简单的 hello world 模块

我正在尝试在 nginx 服务器中实现一个简单的 Hello World 模块。以下是有关 nginx 服务器和我正在使用的模块的一些详细信息:

root@ubuntu:/etc/nginx# nginx -V
nginx version: nginx/1.4.1
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --with-pcre-jit --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.4.1/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.4.1/debian/modules/nginx-dav-ext-module --add-module=/build/buildd/nginx-1.4.1/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.4.1/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.4.1/debian/modules/ngx_http_substitutions_filter_module

我正在使用来自此链接的 hello world 模块:你好世界模块

我没有对它进行任何更改。然后我使用了./configure --add-module=/home/user/module/nginx_module。其中nginx_module目录包含config文件和ngx_http_hello_world_module.c文件。

root@ubuntu:/home/user/Downloads/nginx-1.4.4# ./configure --add-module=/home/user/module/nginx_module

configuring additional modules
adding module in /home/user/module/nginx_module
 + ngx_http_hello_world_module was configured

nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

然后make

cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g   -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/mail \
        -o objs/addon/nginx_module/ngx_http_hello_world_module.o \
        /home/user/module/nginx_module/ngx_http_hello_world_module.c

objs/addon/nginx_module/ngx_http_hello_world_module.o \
    objs/ngx_modules.o \

make install。完成此操作后,我将以下代码添加到/usr/nginx/nginx.conf file

server {
                listen 80;
                server_name localhost;

                location = /hello_world {
                        hello_world;
                        hello_world_string "Sample Message";
                }
       }

然后使用该命令重新加载配置文件后出现以下错误:

root@ubuntu:/home/user# nginx -s reload
nginx: [emerg] unknown directive "hello_world" in /etc/nginx/nginx.conf:79

谁能告诉我哪里做错了吗?

更新: 1) whereis nginx给出以下路径:

root@ubuntu:/home/user/Downloads/nginx-1.4.4# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/local/nginx /usr/share/nginx /usr/share/man/man1/nginx.1.gz

相关内容