Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

So I ran into this problem. I was trying to use the ngx_http_realip_module module to forward the correct remote address for an nginx install behind a load balancer.

Using the directive:

    set_real_ip_from   10.0.0.0/8;
    set_real_ip_from   172.16.0.0/12;
    set_real_ip_from   192.168.0.0/16;
    real_ip_header     X-Forwarded-For;

Resulted in nginx: [emerg] unknown directive "set_real_ip_from  " in /etc/nginx/conf.d/example.org.conf:6

Even though ngx_http_realip_module was installed:

$ nginx -V
nginx version: nginx/1.4.7
built by gcc 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/usr/share/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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ld-opt=' -Wl,-E'
share|improve this question

1 Answer 1

Looking at the error message a little closer answered my question. The directive it could not identify was "set_real_ip_from  " not ]"set_real_ip_from"`.

Apparently, white space matters in nginx configuration files. Turns out the configuration (which I must have pasted in from somewhere) had special non-breaking spaces in it. That'll teach me to copy and paste configuration rather than typing it in.

Changing the lines to:

    set_real_ip_from 10.0.0.0/8;
    set_real_ip_from 172.16.0.0/12;
    set_real_ip_from 192.168.0.0/16;
    real_ip_header X-Forwarded-For;

Solved the problem.

share|improve this answer
1  
Guess it was some weird space character like non-breakable space. –  Alexey Ten Apr 24 at 14:28
    
That must be it. I've tried adding spaces and tabs since and it still works, the config was copied from the web which must have had that non-breaking space. –  Jordan Reiter Apr 24 at 14:30
    
Don't edit configuration files in Microsoft Office? :) –  Michael Hampton Apr 24 at 17:20
    
I was editing it in the terminal! I copied the config from somewhere; I'm guessing that's where the problem came from. –  Jordan Reiter Apr 24 at 19:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.