How to recompile Nginx with changes?

When a particularly long string gets printed to error.log the string gets cut off at the end and "…" is shown (without the quotes) to indicate it's been cut off.

I'm using Nginx with MySQL, PHP and Laravel if that matters. Basically when I print something to the error log like the following:

error_log(print_r($long_str, TRUE));

If $long_str is long enough it gets cut off. I'm using this for debugging purposes and this worked fine when I was working in Apache so I think it may have something to do with Nginx.

I've tried changing…

log_errors_max_len = 1024

to

log_errors_max_len = 60000

in both /etc/php5/cli/php.ini and /etc/php5/fpm/php.ini

But it didn't do anything. After googling around a bit I found:

"There is a hard-coded length limitation on the error messages in the Nginx core. It is 2048 bytes at most, including the trailing newlines and the leading timestamps. You can manually modify this limit by modifying the NGXMAXERRORSTR macro definition in the src/core/ngxlog.h file in the Nginx source tree. If the message size exceeds this limit, the Nginx core will truncate the message text automatically."

I currently have Nginx already installed on my Linode. So that brings me to the question, how can I modify this src/core/ngx_log.h file, as it doesn't seem to be on my Linode, and recompile?

3 Replies

You need to download the source code matching the package you are using, make the change, and then create a new set of binary packages from the modified source. Fortunately, most of the process is completely automated. On Debian/Ubuntu, it would be something like this:

sudo apt-get install build-essential fakeroot
sudo apt-get build-dep nginx
apt-get source nginx
cd nginx-1.6.2
nano src/core/ngx_log.h (make whatever change)
nano debian/changelog (write a changelog entry explaining what you did, increase version number by 0.5)
dpkg-source --commit
dpkg-buildpackage -uc -us

Then you either use "dpkg -i" to install the new packages or put them in a private repository to be installed with apt-get install.

Wish you luck.

Thank you for the helpful reply.

I'm using Ubuntu and will be trying out what you suggested really soon. I'm assuming that I would have to shut down nginx before installing it correct? I've never done this before so I'm thinking I should back up everything before I give it a go.

@rotaercz:

I'm assuming that I would have to shut down nginx before installing it correct?
No, you don't have to worry about that. The Debian packaging system does upgrades "in place" and takes care of that.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct