Apache2 mod_geoip CentOS うざい国を弾くモジュール

GEOIPをyumのリポリトジを利用しインストール
# yum install geoip –enablerepo=rpmforge

yumで見当たらないのでmod_geoipをrpmでダウンロードしてインストールする
# wget ftp://ftp.univie.ac.at/systems/linux/fedora/epel/5/i386/mod_geoip-1.2.5-2.el5.i386.rpm
# rpm -ivh mod_geoip-1.2.5-2.el5.i386.rpm

インストールされたか確認する
# ls /usr/lib/httpd/modules/mod_geoip.so

IPのデータベースを更新する
(デフォルトのdatファイルを使ったところ誤認があったので更新することを推薦します)
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
# gunzip GeoIP.dat.gz
# mv -f GeoIP.dat /usr/share/GeoIP/GeoIP.dat

1ヶ月ごとに更新されるようなので1ヶ月ごとにデータベースを更新させる
# vi /etc/cron.monthly/geoip

1
2
3
gunzip GeoIP.dat.gz
mv -f GeoIP.dat /usr/share/GeoIP/GeoIP.dat

実行権を追加する
# chmod 755 /etc/cron.monthly/geoip

Apacheの設定ファイルに下記を追記(下のサンプルは日本とアメリカ以外の殆どの国を指定してます)
# vi /etc/httpd/conf.d/mod_geoip.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<Location />
Order allow,deny
SetEnvIf GEOIP_COUNTRY_CODE O1 BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AX BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE BZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CX BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE CZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE DZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ER BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ES BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ET BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE FR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE GY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ID BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE JE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE JM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE JO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE LY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ME BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ML BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MQ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MX BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE MZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NP BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE OM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE QA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SB BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ST BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TD BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TH BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TJ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TL BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TO BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TV BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UY BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE UZ BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VC BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VI BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE VU BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE WF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE WS BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE YE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE YT BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ZA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ZM BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE ZW BlockCountry
Deny from env=BlockCountry
Allow from all
</Location>

規制してる海外のプロキシサーバ経由でアクセスしてページがエラー403になってたら成功です

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(Spamcheck Enabled)

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)