gpt4 book ai didi

ruby-on-rails - Nginx - 如何配置 IP 地址? (仅返回 127.0.0.1)

转载 作者:行者123 更新时间:2023-12-04 20:45:01 26 4
gpt4 key购买 nike

我在 Amazon EC2 上有一个 Rails 应用程序,使用 nginx 和 unicorn。

当我访问 request.remote_ip request.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

我究竟做错了什么?有没有其他bug?

最佳答案

尝试这个 :

proxy_set_header CLIENT_IP $remote_addr;

关于ruby-on-rails - Nginx - 如何配置 IP 地址? (仅返回 127.0.0.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19329162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com