Storing $server_addr in a variable VS using it directly in location block

justink101 nginx-forum at nginx.us
Wed Jul 15 01:46:58 UTC 2015


According to the documentation getting the value of $server_addr to set a
response header makes a system call, and can impact performance
negativelyset $ip $server_addr;

    server {
        location /health {
            add_header Backend $server_addr;
            return 200;
        }
    }

Would the following be a better solution, and eliminate the system call on
every request?

    server {
        set $ip $server_addr;

        location /health {
            add_header Backend $ip always;
            return 200;
        }
    }

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,260304,260304#msg-260304



More information about the nginx mailing list