nginx-error_log重定向

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx-error_log重定向相关的知识,希望对你有一定的参考价值。

  • 编译模块
 -bash-4.1# ./sbin/nginx -V
nginx version: nginx/
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-http_stub_status_module --error-log-path=/usr/local/nginx/log/error.log
  • nginx主配置文件

 -bash-4.1# cat conf/nginx.conf
worker_processes  1;
error_log /usr/local/nginx/log/error.log;

events {
    worker_connections  1024;
}

http {
     include mime.types;
     default_type application/octet-stream;
     sendfile on;
     keepalive_timeout 65;
     include  test/*;
}
  • 测试
 -bash-4.1# > log/error.log
-bash-4.1# > logs/error.log
-bash-4.1# sed ‘s/(^error_log.*)/1
access_log  /usr/local/nginx/log/access.log;/‘ conf/nginx.conf
worker_processes  1;
error_log /usr/local/nginx/log/error.log;
access_log  /usr/local/nginx/log/access.log;

events {
    worker_connections  1024;
}

http {
     include mime.types;
     default_type application/octet-stream;
     sendfile on;
     keepalive_timeout 65;
     include  test/*;
}
-bash-4.1# sed -i ‘s/(^error_log.*)/1
access_log  /usr/local/nginx/log/access.log;/‘ conf/nginx.conf
-bash-4.1# ./sbin/nginx -t
nginx: [emerg] "access_log" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:3
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
-bash-4.1# ./sbin/nginx -s reload
nginx: [emerg] "access_log" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:3
-bash-4.1# cat log/error.log 
2018/08/24 14:45:43 [emerg] 5258#0: "access_log" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:3
2018/08/24 14:45:47 [emerg] 5267#0: "access_log" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:3
-bash-4.1# cat logs/error.log 
-bash-4.1# 
  • 复原
-bash-4.1# sed -i ‘3d‘ conf/nginx.conf
-bash-4.1# cat conf/nginx.conf
worker_processes  1;
error_log /usr/local/nginx/log/error.log;

events {
    worker_connections  1024;
}

http {
     include mime.types;
     default_type application/octet-stream;
     sendfile on;
     keepalive_timeout 65;
     include  test/*;
}
-bash-4.1# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
-bash-4.1# ./sbin/nginx -s reload

以上是关于nginx-error_log重定向的主要内容,如果未能解决你的问题,请参考以下文章

Jsp获取Java的重定向赋值(String)

302 登录重定向后被 IE 删除的 URL 片段

链接中的 URL 片段和 JSF 中的 ajax 重定向

使用片段 (#) 重定向链接 - asp.net

在 PHP 重定向期间处理片段标识符

重定向时如何在 Safari 中保留 uri 片段?