Firstly, backup your nginx config folder (/etc/nginx) - if your configs are valuable to you, then you certainly need an extra copy in case anything goes wrong. That said, most installations do not overwrite the existing configs.
Secondly, for a proper configure line, run
nginx -V (with your working nginx), and then add the additional configure statement, there are likely other configuration parameters that are relevant to your setup. (This will also let you verify whether or not the module is already compiled into the version you are running.) (Also, you said it 'didn't work' - why? What was the error?). The default nginx configure statement (x86) is:
--prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx \
--with-http_ssl_module --with-http_realip_module --with-http_addition_module \
--with-http_sub_module --with-http_dav_module --with-http_flv_module \
--with-http_mp4_module --with-http_gzip_static_module \
--with-http_random_index_module --with-http_secure_link_module \
--with-http_stub_status_module --with-mail --with-mail_ssl_module \
--with-file-aio --with-ipv6 --with-cc-opt='-O2 -g -march=i386 -mtune=i686'
Finally, if you don't have specific optimizations in place (e.g. you have removed certain modules, etc) you can use the nginx repository (available for RHEL/CentOS, Debian/Ubuntu) - the published binaries include the module you are looking for (as per the config statement above) and the repository makes it easier to maintain (the downside being the lack of customization, but sometimes, it is a worthwhile price to pay).
The repository version does not overwrite your configurations, but if there are new config files it will add them - this has been an issue for some configurations with the newer versions, since /etc/nginx/conf.d/default.conf is added - which specifies an additional server that may not be compatible with existing configurations. (You can just rename this file, or even copy back your entire /etc/nginx folder to restore your old config)