运行 RedMine 时如何更改 WEBrick :AccessLog 选项?

问题描述 投票:0回答:1

我使用以下命令行(简化)通过 WEBrick 运行 RedMine:

bundle exec rails server webrick -e production -p 3012 -P '/var/lib/redmine/redmine.pid'

我不喜欢 WEBrick 在访问日志行开头输出对等地址的方式(因为我在 nginx 后面运行它,对等地址始终是 127.0.0.1),所以我想更改访问日志格式。

我知道我需要调整 WEBrick 的

:AccessLog
配置选项,但我不知道如何掌握它。 WEBrick 由
rails server
命令通过
rack
抽象运行,我没有看到将必要的配置传递给 WEBrick 的明显方法。

那么,有什么办法可以做到吗?一些命令行开关?

-c
是唯一接受某种配置文件的交换机,但它引用了“rackup”,我不知道如何使用它。

也许可以通过更改配置文件来完成?我尝试通过添加

additional_environment.rb
来修改
config[:AccessLog] = [ [ $stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT ] ]
,但它没有效果(尽管文件已执行),所以我假设该文件的
config
不是传递给 WEBrick 的内容。

我非常确定有某种方法可以配置此选项,无需创建新的 Rails 应用程序并手动调用 WEBrick,甚至希望无需更改 RedMine 文件。

ruby-on-rails redmine webrick
1个回答
0
投票

我不确定这是否符合你的问题,我不知道 RedMine。

但是:

使用 Rails,您可以通过以下方式访问 webrick:

::WEBrick::Config::HTTP[:AccessLog] #leading :: depend on installation

我将此行放入我的应用程序中。rb

WEBrick::Config::HTTP[:AccessLog]=[[STDOUT, format_in_accesslog.rb ]]

喜欢

WEBrick::Config::HTTP[:AccessLog]=[[Logger.new(STDOUT), "%h %l %u %t \"%r\" %s %b"]]    

accesslog.rb
你会发现

# This format specification is a subset of mod_log_config of Apache:
#
# %a:: Remote IP address
# %b:: Total response size
# %e{variable}:: Given variable in ENV
# %f:: Response filename
# %h:: Remote host name
# %{header}i:: Given request header
# %l:: Remote logname, always "-"
# %m:: Request method
# %{attr}n:: Given request attribute from <tt>req.attributes</tt>
# %{header}o:: Given response header
# %p:: Server's request port
# %{format}p:: The canonical port of the server serving the request or the
#              actual port or the client's actual port.  Valid formats are
#              canonical, local or remote.
# %q:: Request query string
# %r:: First line of the request
# %s:: Request status
# %t:: Time the request was received
# %T:: Time taken to process the request
# %u:: Remote user from auth
# %U:: Unparsed URI
# %%:: Literal %

语法是

[[out, format],[out, format]]

© www.soinside.com 2019 - 2024. All rights reserved.