Nginxメモ

いやもー、ぜんっぜん分かりませんからぁぁぁ(泣)
if とか見たくも無いのにorz マジ勘弁して(T-T)

/etc/nginx/conf.d/kusanagi_html_http.conf

location / {
try_files $uri $uri/ /index.php?$args;
}

if ($http_referer ~* (blog.goo.ne.jp|desktop2ch.net|2ch.net|ime.nu|l.moapi.net) ){
return 403;
break;
}

太字部分をこっそり追記でリファラーによるアクセス制限
自分じゃ動作確認出来てないんだけどネ………うまく動いてるといいなァ(遠い目

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

ログ取り。

/etc/nginx/nginx.conf に追記

geo $internal_access {
default off;
192.168.1.1 on;
127.0.0.1 on;
}
map $internal_access $mainlog {
off 1;
default 0;
}

map $internal_access $internallog {
off 0;
default 1;
}

/etc/nginx/conf.d/kusanagi_html_http.conf にも追記

access_log /home/kusanagi/kusanagi_html/log/nginx/blog-access.log main if=$mainlog;
access_log /home/kusanagi/kusanagi_html/log/nginx/home-access.log main if=$internallog;
error_log /home/kusanagi/kusanagi_html/log/nginx/error.log warn;

ーーーーーーーーーーーーーーーーーーーーーーーーーー

http ⇒ https へ強制転送
/etc/nginx/conf.d/kusanagi_html_http.conf に追記

server {
listen 80;
server_name new.lacus.to;
return 301 $host$request_uri;

1行追加するだけ。とっても楽ちんw

Apacheだったらこんなに楽だったのに………orz ログ取りは /etc/httpd/conf.d/kusanagi_html_ssl.conf のバーチャルホスト内に記述
SetEnvIf Remote_Addr 1**.**1.1**.7 homelog2 no_log
SetEnvIf Remote_Addr fp**f***0*.tkyc***.ap.nuro.jp homelog2 no_log
SetEnvIf Remote_Addr 2**.**.***.1** homelog2 no_log
SetEnvIf Remote_Addr k******.ppp.asahi-net.or.jp homelog2 no_log
CustomLog /home/kusanagi/kusanagi_html/log/httpd/home_log.log common env=homelog2
CustomLog /home/kusanagi/kusanagi_html/log/httpd/ssl_access.log combined env=!no_log

ーーーーーーーーーーーーーーー

アクセス制限は .htaccess で

SetEnvIf Referer “^http://blog\.goo\.ne\.jp” chk_url
SetEnvIf Referer “^https://blog\.goo\.ne\.jp” chk_url
SetEnvIf Referer “^http://desktop2ch\.net” chk_url
SetEnvIf Referer “^https://desktop2ch\.net” chk_url
SetEnvIf Referer “^http://2ch\.net” chk_url
SetEnvIf Referer “^https://2ch\.net” chk_url
SetEnvIf Referer “^http://ime\.nu” chk_url
SetEnvIf Referer “^https://ime\.nu” chk_url
SetEnvIf Referer “^http://l\.moapi\.net” chk_url
SetEnvIf Referer “^https://l\.moapi\.net” chk_url

order allow,deny
allow from all
deny from env=chk_url

Nginxの設定ファイルは美しいという人も居る………プログラマだろそれ!!(>_<);

http:// へのアクセスを全て https:// へ流す書式。 これも .htaccess で

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI} [R=301,L]

この2行がたった1行で済むのはNginxの方が優秀かな。

コメントを残す

メールアドレスが公開されることはありません。