【问题标题】:nginx c module hello world doesn't worknginx c模块hello world不起作用
【发布时间】:2017-09-15 11:35:37
【问题描述】:

我只是下载nginx。然后我进入nginx的目录,将三个命令一一执行如下:

./configure
make
make install

然后我可以访问http://localhost,一切顺利。

现在我正在尝试添加一个 c 模块。这是hello world example。

我所做的是从 Github 下载示例并编辑 nginx (/pathOfNginx/conf/nginx.conf) 的配置文件如下:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        ############ this is what I add
        location /test {
            hello_world;
        }
        ############ done
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

在那之后,我做./configure --add-module=/path/to/nginx-hello-world-module 和make。一切看起来都不错。
然后我重新加载服务器:nginx -s reload

但是,我无法得到正确的答复。这意味着当我执行 curl -i http://localhost/test 时,我得到的是 404 Not Found,而不是 hello world 字符串。

【问题讨论】:

    标签: c nginx module


    【解决方案1】:

    它对我有用!

    给出一个包含hello world\0的文件...

    请记住,第二次运行 ./configure 时,您需要再次提供所有选项(它是替换配置,而不是更新配置)。

    您还需要在后面加上make install,否则安装的二进制文件将不会更新。

    # get everything
    wget http://nginx.org/download/nginx-1.12.0.tar.gz
    tar -xvf nginx-1.12.0.tar.gz
    git clone https://github.com/perusio/nginx-hello-world-module
    
    # configure
    (
      cd nginx-1.12.0
      ./configure --prefix=../nginx --add-module=../nginx-hello-world-module/
    )
    
    # build & install
    make -C ./nginx-1.12.0 -j8
    make -C ./nginx-1.12.0 install
    
    # update config
    cat <<EOF >./nginx/conf/nginx.conf
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            }
            ############ this is what I add
            location /test {
                hello_world;
            }
            ############ done
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }
    EOF
    
    # run
    (
        cd nginx
        ./sbin/nginx
    )
    
    # test
    curl http://localhost:80/test
    

    【讨论】:

    • 我想我找到了原因:当我重新编辑pathOfNginx/nginx/conf/nginx.conf 时,/usr/local/nginx/conf 无法更新。我不确定我应该为这个问题做些什么。现在,我能做的就是rm -rf /usr/local/nginx 并重新配置和重新制作整个 nginx。
    猜你喜欢
    • 2013-12-06
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多