回答
收藏
分享
举报
Nginx API接口
提问于2020-09-25 20:39

浏览 4.2k

开源版本的Nginx 有没有API接口可以调用给第三方使用。

已修改于2023-03-17 18:12



写下您的回答
发表回答
全部回答(1)

按点赞数排序

按时间排序

没有,N+才有

赞同

1

回复举报

回答于2020-09-30 13:29



回复陶辉
回复
提问者
浩聪
这家伙很懒还未留下介绍~
5
文章
15
问答
0
粉丝
相关问答

介绍在nginx中自定义请求头字段,并在日志中展示相关字段的值: 

第一种方法: 

1 在代理nginx服务器配置中增加两个proxy_set_header字段,一个iden,一个age,分别赋值为"student","21",我们将来在日志中看到这两个常量;

server {

    server_name 127.0.0.1;

    listen 80;

    location /header {

        default_type "text/plain";

        access_log /data/nginx/log/proxy_header.log api;

        proxy_redirect     off;

        proxy_set_header   iden    "student";

        proxy_set_header   age     "21";

        proxy_set_header   Host    $host;

        proxy_pass http://127.0.0.1:88;

     } 

}

此时代理nginx将请求头重写,传入后端服务器,所以在此nginx服务器日志上看不到相关字段信息,为了演示方便,将此服务转发到同机器88端口的服务上;


2 配置后端服务相关配置:端口号88,返回200;

server {

    server_name 127.0.0.1;

    listen 88;


    location / {

        access_log /data/nginx/log/proxy_header.log api;

        proxy_redirect     off;

        proxy_set_header   Host    $host;

        default_type "text/plain";

        return 200 "OK";

    }

}


3 在 api的log_format中,增加两个字段;

"$http_iden" "$http_age"


4 curl 测试接口;

curl http://127.0.0.1/header


5 查看日志;

image.png

发现第一条日志记录有相关字段信息,是后端nginx服务的日志信息;第二条日志无字段相关信息,是代理nginx服务器的日志;


结论:使用proxy_set_header自定义字段时,后端服务器日志能获取到自定义的相关信息;


第二种方法:

1 在代理nginx服务器中配置set 关键字,定义两个字段,同样转发到统计器的88端口;

server {

    server_name 127.0.0.1;

    listen 80;

    location /header {

        set $iden "student";

        set $age "21";

        default_type "text/plain";

        access_log /data/nginx/log/proxy_header.log api;

        proxy_redirect     off;

        proxy_set_header   Host    $host;

        proxy_pass http://127.0.0.1:88;

    }


}


2 配置后端服务相关配置:端口号88,返回200,与第一种方法保持一致;

server {

    server_name 127.0.0.1;

    listen 88;


    location / {

        access_log /data/nginx/log/proxy_header.log api;

        proxy_redirect     off;

        proxy_set_header   Host    $host;

        default_type "text/plain";

        return 200 "OK";

    }

}


3 修改api的log_format中的两个字段;

"$iden" "$age"


4 curl 测试接口;

curl http://127.0.0.1/header


5 查看日志;

image.png

发现第一条日志记录无相关字段信息,是后端nginx服务的日志信息;第二条日志有字段相关信息,是代理nginx服务器的日志;

点赞 0
浏览 6.2k
解决思路:
1:这里的signal 表示的是nginx的型号,找到对应25 对应的错误标签意思
signal各个数字含义
signal.h中是如下定义的: #include <machine/signal.h>/* sigcontext; codes for SIGILL, SIGFPE */ #defineSIGHUP 1/* hangup */ #defineSIGINT 2/* interrupt */ #defineSIGQUIT 3/* quit */ #defineSIGILL 4/* illegal instruction (not reset when caught) */ #defineSIGTRAP 5/* trace trap (not reset when caught) */ #defineSIGABRT 6/* abort() */ #if  (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)) #defineSIGPOLL 7/* pollable event ([XSR] generated, not supported) */ #else/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ #defineSIGIOT SIGABRT/* compatibility */ #defineSIGEMT 7/* EMT instruction */ #endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ #defineSIGFPE 8/* floating point exception */ #defineSIGKILL 9/* kill (cannot be caught or ignored) */ #defineSIGBUS 10/* bus error */ #defineSIGSEGV 11/* segmentation violation */ #defineSIGSYS 12/* bad argument to system call */ #defineSIGPIPE 13/* write on a pipe with no one to read it */ #defineSIGALRM 14/* alarm clock */ #defineSIGTERM 15/* software termination signal from kill */ #defineSIGURG 16/* urgent condition on IO channel */ #defineSIGSTOP 17/* sendable stop signal not from tty */ #defineSIGTSTP 18/* stop signal from tty */ #defineSIGCONT 19/* continue a stopped process */ #defineSIGCHLD 20/* to parent on child stop or exit */ #defineSIGTTIN 21/* to readers pgrp upon background tty read */ #defineSIGTTOU 22/* like TTIN for output if (tp->t_local<OSTOP) */ #if  (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) #defineSIGIO 23/* input/output possible signal */ #endif #defineSIGXCPU 24/* exceeded CPU time limit */ #defineSIGXFSZ 25/* exceeded file size limit */ #defineSIGVTALRM 26 /* virtual time alarm */ #defineSIGPROF 27/* profiling time alarm */ #if  (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) #define SIGWINCH 28/* window size changes */ #define SIGINFO29 /* information request */ #endif #define SIGUSR1 30/* user defined signal 1 */ #define SIGUSR2 31/* user defined signal 2 */ Exception codes In the crash log is a line that starts with the text Exception Codes: followed by one or more hexadecimal values. These are processor-specific codes that may give you more information on the nature of the crash. The exception code 0xbaaaaaad indicates that the log is a stackshot of the entire system, not a crash report. To take a stackshot, push the home button and any volume button. Often these logs are accidentally created by users, and do not indicate an error. The exception code 0xbad22222 indicates that a VoIP application has been terminated by iOS because it resumed too frequently. The exception code 0x8badf00d indicates that an application has been terminated by iOS because a watchdog timeout occurred. The application took too long to launch, terminate, or respond to system events. One common cause of this is doing synchronous networking on the main thread. Whatever operation is on Thread 0: needs to be moved to a background thread, or processed differently, so that it does not block the main thread. The exception code 0xc00010ff indicates the app was killed by the operating system in response to a thermal event. This may be due to an issue with the particular device that this crash occurred on, or the environment it was operated in. For tips on making your app run more efficiently, see iOS Performance and Power Optimization with Instruments WWDC session. The exception code 0xdead10cc indicates that an application has been terminated by iOS because it held on to a system resource (like the address book database) while running in the background. The exception code 0xdeadfa11 indicated that an application has been force quit by the user. Force quits occur when the user first holds down the On/Off button until "slide to power off" appears, then holds down the Home button. It's reasonable to assume that the user has done this because the application has become unresponsive, but it's not guaranteed - force quit will work on any application. Note: Terminating a suspended app by removing it from the multitasking tray does not generate a crash log. Once an app has suspended, it is eligible for termination by iOS at any time, so no crash log will be generated.
查看到 signal 25 表示的是exceeded file size limit 超出文件大小限制
通过排查是由于 access.log 文件太大,超过了 设置的最大值,删除文件并配置定时备份删除就可以了
点赞 0
浏览 5.6k