2013-10-12 53 views
5

我在Amazon EC2上有一個使用nginx和獨角獸的Rails應用程序。Nginx - 如何配置IP地址? (僅返回127.0.0.1)

當我訪問request.remote_iprequest.env [ 'REMOTE_ADDR'],輸出總是127.0.0.1

這裏是我的nginx.conf

user www-data; 
worker_processes 1; 

error_log /var/log/nginx/error.log; 
pid  /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
    # multi_accept on; 
} 

http { 
    include  /etc/nginx/mime.types; 

    access_log /var/log/nginx/access.log; 

    sendfile  on; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 
    tcp_nodelay  on; 

    gzip on; 
    gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 

    upstream example.com { 
     server 127.0.0.1:8080; 
    } 

    server{ 
     listen 80; 

     server_name example.com _; 
     root /home/deployer/example/public; 

     location/{ 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     #proxy_set_header X_FORWARDED_PROTO $scheme; 
     proxy_set_header Host $http_host; 

     if (!-f $request_filename) { 
      proxy_pass http://example.com; 
      break; 
     } 
     if (-f $document_root/system/maintenance.html) { 
      return 503; 
     } 
     } 
    } 
} 

我試圖添加這些行:

proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

但不幸的是,結果還是一樣 - 127.0.0.1

什麼我做錯了嗎?有沒有其他的錯誤?

+0

同樣在這裏!使用龍捲風web服務器作爲上游。任何幫助,將不勝感激! –

回答

2

試試這個:

proxy_set_header CLIENT_IP $remote_addr; 
+0

我試過了,但還是一樣的。 – user984621

+0

您每次更改配置時是否重新啓動服務器? –

+0

應該是'Client-IP',而不是'CLIENT_IP'。 –