最近接手一个问题 在每次出现404的情况时:需要在响应的内容中,添加 request_uri remote_ip 等一些内容。 开始的时候 发现一个模块 --with-http_sub_module 可以对响应内容进行一个替换修改 但是这个模块需要从新对nginx进行编译,在编译的时候添加模块 --prefix=/usr/local/nginx --with-http_sub_module 然后就可以在nginx.conf中使用了 sub_filter thisisatestipaddr 'ipaddr:$remote_addr \nrequest_url:$server_name$request_uri \nstatus:$status'; sub_filter_types *; sub_filter_once on; 但是由于我的nginx不是做web的,他是用来做代理的。而且还不想在后端web服务器上指定404页面,找到一个模块 error_page可以指定404页面跳转,但是在nignx做代理的情况下error_page 不生效。后来发现在location下添加 proxy_intercept_errors on; proxy_redirect default; proxy_intercept_errors 语法:proxy_intercept_errors [ on|off ] 并且把404跳转重新指定一个模块就可以了。整体的配置如下: http{ fastcgi_intercept_errors on; #启用error_page server{ error_page 404 /404.html; #指定跳转页面 location = /404.html { #页面存放在本地的目录 root html; sub_filter thisisatestipaddr 'ipaddr:$remote_addr \nrequest_url:$server_name$request_uri \nstatus:$status'; sub_filter_types text/html; sub_filter_once on; } location /{ proxy_pass http://www.; proxy_intercept_errors on; proxy_redirect default; } }
} |
|
来自: waitingnothing > 《Nginx》