私は ip2location を使用していますが、ロード バランサーの背後にない私のサイトでは問題なく動作します。
F5 または AWS ELB の背後にあるものはすべて、空の文字列を返します
私は ip2location のモジュールを調べ始め、代わりに X_FORWARDED_FOR を取得するように変更しようとしていました。
ここに mod_ip2location.c があります
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_log.h"
#include "ap_config.h"
#include "apr_strings.h"
#include "IP2Location.h"
static const int ENV_SET_MODE = 0x0001;
static const int NOTES_SET_MODE = 0x0002;
static const int ALL_SET_MODE = 0x0003;
typedef struct {
int enableFlag;
int setMode;
char* dbFile;
IP2Location* ip2locObj;
} ip2location_server_config;
module AP_MODULE_DECLARE_DATA IP2Location_module;
static apr_status_t ip2location_cleanup(void *cfgdata) {
// cleanup code here, if needed
return APR_SUCCESS;
}
static void ip2location_child_init(apr_pool_t *p, server_rec *s) {
apr_pool_cleanup_register(p, NULL, ip2location_cleanup, ip2location_cleanup);
}
static int ip2location_post_read_request(request_rec *r) {
char* ipaddr;
ip2location_server_config* config;
IP2LocationRecord* record;
char buff[20];
config = (ip2location_server_config*)
ap_get_module_config(r->server->module_config, &IP2Location_module);
if(!config->enableFlag)
return OK;
ipaddr = r->connection->remote_ip;
record = IP2Location_get_all(config->ip2locObj, ipaddr);
if(record) {
if(config->setMode & ENV_SET_MODE) {
apr_table_set(r->subprocess_env,
この行を変更しようとしました:
ipaddr = r->connection->remote_ip;
に
ipaddr = r->header_in('X-Forwarded-For');
コンパイルされず、エラーが発生します
関数 'ip2location_post_read_request': エラー: 'request_rec' には 'header_in' という名前のメンバーがありません 警告文字定数がその型に対して長すぎます
見落としている簡単な修正があるかどうかわかりませんか?ありがとう!