您的位置:首页 > 运维架构 > Nginx

nginx 开发第三方模块的时调式日志的方法(终端printf输出日志)

2018-02-06 10:30 555 查看
最近在利用nginx做web后端服务开发,做第三方http模开发,无聊记录一哈操作nginx的方法(日志debug,启动,ngin.conf配置等等)
开启调试日志: 要开启调试日志,首先需要在配置Nginx时打开调试功能,然后编译:
./configure --with-debug ...


2.修改nginx.conf文件
daemon off;
master_process off;


daemon off; 作用是关闭nginx在后台启动(守护进程的模式)

master_process off; 关闭创建子进程

以上都是设置好了就可以和平时一样启动nginx了,在控制台(终端上)显示你代码中格式printf打印日志的方法,输出变量的值调试代码了。

nginx的启动:
./bin/sbin/nginx


nginx的关闭:

第一种方法:
ps -ef |grep nginx
kill -9  进程id


第二方法:
./bin/sbin/nginx  -s stop


我的nginx.conf文件
#user  nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;
daemon off; master_process off;

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;

#post server
server {
listen 8018;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;
access_log logs/post.log main;

location / {
root html;
index index.html index.htm;
}

location /v1
{
if ($request_method = GET )
{
return 403;
}
mytest;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root html;
}
}

#get service
server {
listen 8017;
server_name localhost;

access_log logs/get.log main;
#access_log off;

location /
{
root html;
index index.html index.htm;
}

location /hello
{
if ($request_method = POST )
{
return 403;
}
mytest;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root html;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: