スキップしてメイン コンテンツに移動

投稿

ラベル(apache)が付いた投稿を表示しています

.htaccessで403を404で返す

久しぶりにリライトルールを書いたよ。 ドキュメントルートに.htaccessを置く場合の記述↓ # 403.html は実体がなくてよい。RewriteRule により 404 リダイレクトが発生するので、あっても使われない。 ErrorDocument 403 /403.html # 独自の404ページをドキュメントルートに用意するならこんな感じ。 ErrorDocument 404 /404.html RewriteEngine On # 403 Forbidden を 404 Not Found で返す。独自の404ページがあれば、それが表示される。 RewriteRule 403.html - [R=404,L]

VirtualHost とデフォルトサイト

これは常識なのかもしれないけど、 ・サイトは、すべて VirtualHost で定義する。 ・VirtualHost 定義の一番先頭に、 <VirtualHost *:80> </VirtualHost> ってだけ書いておく。 ・IP直打ちでアクセスされたときのために、デフォルトのドキュメントルート(/var/www/html)は空にしておく。 ・VirtualHostの定義は、httpd.conf の一番最後で行う。サイトごとに別ファイルで定義するときは、httpd.conf の一番最後で Include する。 ・名前ベースのバーチャルホストでSSLする。 ってことをするようにした。 こうすることで、 ・IP直打ちアクセスや意図しないHOST_NAMEでのアクセスは、全部、デフォルトのドキュメントルートへ流す。 ことができて、これらの意図しないアクセスはすべて 403 で捌けるなと。 でも、その前の前提として、httpd.conf で <Directory "/var/www/html">  Options -Indexes +FollowSymLinks ・・・ </Directory> ってしておくことと、 # rm /etc/httpd/conf.d/welcome.conf  って消しておいてね

http/https のセッション数 を netstat の state ごとに表示する

watch使う場合、sed -e 's/[^A-Z]*//' がみそ。 もし sed -e 's/[^A-Z]*//' がなかった場合どうなるかは、試してみて。 watch -n 1 "netstat -ant | egrep ':(80|443) '| egrep 'EST|SYN|FIN|CLOSE'| awk {'print $6'} | sed -e 's/[^A-Z]*//' | sort | uniq -c" こんなのも watch -n 2 "netstat -etpon | egrep ':(80|443) ' | egrep 'EST|SYN|FIN|CLOSE'"

Aレコードさえあればメールは届く

俺:80%?冗談じゃない、この設定で100%メールは届きます。 無能:MXレコードは定義されていない? 俺:あんなの飾りです。MXレコードなんてなくても、www.example.comでAレコードさえ定義してあれば、 apache@www.example.com っていう Return-Path にも、メールは返ってくるんです。

apache 2.4 の ServerName

[root@sv00 ~]# cat /etc/httpd/conf/httpd.conf ~ #ServerName www.example.com:80 ~ <VirtualHost *:80> # Default VirtualHost # Use Main Setting </VirtualHost> <VirtualHost *:80> ServerName sv01.example.dom DocumentRoot /var/www/html/sv01 </VirtualHost> [root@sv00 ~]# hostname sv00.example.com [root@sv00 ~]# httpd -S VirtualHost configuration: *:80 is a NameVirtualHost default server sv00.example.com (/etc/httpd/conf/httpd.conf:357) port 80 namevhost sv00.example.com (/etc/httpd/conf/httpd.conf:357) port 80 namevhost sv01.example.dom (/etc/httpd/conf/httpd.conf:361) ServerRoot: "/etc/httpd" Main DocumentRoot: "/var/www/html" ~ こんな感じで、hostname が FQDN で設定されていると、default の ServerName は hostname が使用される。 hostname が 「sv00」だけだと [root@sv00 ~]# apachectl configtest AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192:168:0:1. Set the 'ServerName' directive globally to s...

apachectl fullstatus の Request 列の改行を制御する

[root@websv ~] # which apachectl /usr/sbin/apachectl [root@websv ~] # less /usr/sbin/apachectl ... # |||||||||||||||||||| START CONFIGURATION SECTION |||||||||||||||||||| # -------------------- -------------------- # # the path to your httpd binary, including options if necessary HTTPD='/usr/sbin/httpd' # # # a command that outputs a formatted text version of the HTML at the # url given on the command line. Designed for lynx, however other # programs may work. if [ -x "/usr/bin/links" ]; then LYNX="/usr/bin/links -dump" else LYNX=none fi # # the URL to your server's mod_status status page. If you do not # have one, then status and fullstatus will not work. STATUSURL="http://websv:80/server-status" ... [root@websv ~] # man links ... -dump-width (alias for document.dump.width) Width of the dump output. ... [root@websv ~] # /usr/bin/links -dump http://websv:80/server-status/ ... Srv PID Acc M CPU SS Re...

Corosync と Pacemaker でクラスタ化されたサーバのメンテナス

普通に監視対象サービスを停止しちゃうとフェイルオーバーするので、 それを回避する方法。 1.メンテナンスモードを有効にする。 crm configure property maintenance-mode=true 2.必要な作業を行う。 サービス停止してもフェイルオーバーしないので、設定ファイルいじったりできる。 停止したサービスは、起動してから次の手順へ。 停止は crm resource stop リソース名 開始は crm resource start リソース名 再起動は crm resource restart リソース名 ※その他、crmコマンドの詳細は、こちらのサイトがわかりやすかったです。 CRM CLI (command line interface) tool 3.メンテナンスモードを終了する。 crm configure property maintenance-mode=false 以上!

.htaccess の RewriteRule で 正規表現パターンを 「 ^/ 」 から書くな

RewriteEngine On RewriteRule ^/foo/bar\.html$ baz.html [L] って感じで、正規表現パターンを「^/」から始めている記述がネットに散乱してるけど、 RewriteRule に渡ってくるパスが「/」から始まるのは、RewriteRule を httpd.conf に書いたときだけ。 .htaccess に書いたときは、.htaccess が設置されているディレクトリからの相対パス。 よって、.htaccess で 「^/」って書くと、パターンにマッチしない。

RewriteRule の サンプル

Apache HTTP Server Version 2.2 ドキュメント mod_rewrite - RewriteRule ディレクティブ から引用 Inside per-server configuration (httpd.conf) for request GET /somepath/pathinfo: Given Rule Resulting Substitution ---------------------------------------------- ---------------------------------- ^/somepath(.*) otherpath$1 invalid, not supported ^/somepath(.*) otherpath$1 [R] invalid, not supported ^/somepath(.*) otherpath$1 [P] invalid, not supported ---------------------------------------------- ---------------------------------- ^/somepath(.*) /otherpath$1 /otherpath/pathinfo ^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo via external redirection ^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported ---------------------------------------------- ---------------------------...

CentOS + Apache + PHP + PDO で SQL Server へ接続

前提:httpd、phpのインストールが終わっていること # yum install httpd php 作業: # yum install epel-release # vi /etc/yum.repos.d/epel.repo [epel] ~ enabled=0 ~ # yum --enablerepo=epel install php-mssql # vi /etc/freetds.conf ~ [MSSQLSVR2012]         host = 1.2.3.4         port = 1433         tds version = 8.0         charset = CP932         client charset = UTF-8 # vi /etc/selinux/config ~ SELINUX=disabled ~ # restart

wget で負荷テスト

ab だと 同じファイルにしかアクセスできないので、wget 使って負荷テストしてみた。 BASIC認証ありのテストサイトに負荷テストしてみた例。 $ wget -o /var/tmp/wget.log -r -np --spider -t 1 -e robots=off --http-user=hogehoge --http-passwd=hogehoge http://www.example.dom/ ログを書き出す -o /var/tmp/wget.log サイト全体 -r 親階層は見ない -np ファイルの存在確認のみ(ダウンロードしない) --spider 試行回数は1回だけ -t 1 robots.txtを無視 -e robots=off BASIC認証アカウント --http-user=hogehoge --http-passwd=hogehoge テストサイトURL http://www.example.dom/

ついでに調べたLAMPのバージョン(CentOS 5 と CentOS 6)

2014/10/22 時点で、標準リポジトリからインストール可能なバージョンを調べた。 ■ CentOS 5.11 パッケージ名 バージョン httpd 2.2.3-91 php 5.1.6-44 php53 5.3.3-23 mysql-server 5.0.95-5 mysql51-mysql-server 5.1.70-1 mysql55-mysql-server 5.5.37-1 ■ CentOS 6.5 パッケージ名 バージョン httpd 2.2.15-31 php 5.3.3-27 mysql-server 5.1.73-3 # yum install パッケージ名 MySQL5.5は、CentOS 6.5の標準リポジトリからはインストールできないようだ。

CentOS 7 で LAMP (Linux + Apache + MySQL + PHP)

CentOS 7 から MySQL が MariaDB になったので、こんな感じでインストールする。 # yum install httpd mariadb-server php php-mysql 後は、必要なphpモジュールを追加でインストールして終わり。 ちなみに、インストールされたバージョンは、2014/10/21現在でこんな感じ # yum list installed httpd.x86_64 2.4.6-18.el7.centos mariadb-server.x86_64 1:5.5.37-1.el7_0 php.x86_64 5.4.16-23.el7_0.1 MySQL が MariaDB になった理由は、Wikipedia 参照で。 ■ MariaDB - Wikipedia http://ja.wikipedia.org/wiki/MariaDB

共有メモリサイズを知る apacheチューニング ~ COW (Copy on Write) ~

apacheをチューニングする必要があったので、いろいろ調べてた。 ■Linux のプロセスが Copy on Write で共有しているメモリのサイズを調べる http://d.hatena.ne.jp/naoya/20080212/1202830671 ここに載ってるperlのスクリプトを動かそうと思ったら、Perl の Linux::Smaps っていうモジュールが必要だった。 チューニング中のサーバには入れることができなかったので、他の方法を探していたらあった。 ■2010-09-23の技術こねた http://blog.livedoor.jp/kurt0027/archives/52376188.html シェルスクリプトで書かれていたので、早速使ってみた。 ■使い方 例:apache の子プロセスが共有しているメモリサイズを調べる。 # /bin/bash ./smaps.sh $(pgrep -u apache httpd) PID VSZ RSS Shared 21462 89292KB 67748KB 62176KB(92%) 23219 88276KB 65316KB 61160KB(94%) ・・・

スローアタック

スローアタックって? http://www.drk7.jp/MT/archives/001527.html http://2u-moomin.blog.so-net.ne.jp/ http://www.keyman.or.jp/kc/30006788/ 対策 http://code.zobe.jp/2012/10/defense_against_slowhttptest_using_mod_security2_section1/ http://code.zobe.jp/2012/10/defense_against_slowhttptest_using_mod_security2_section2/ http://code.zobe.jp/2012/10/defense_against_slowhttptest_using_mod_security2_section3/ http://code.zobe.jp/2012/10/you_shoud_not_blindly_use_modsecurity2_crs_base_rules/

CentOS 6.3 で確認した Apache アクセスログのローテーション設定

CentOS 6.3 でのお話。 Apacheをyumでインストールすると、Apacheログのローテート設定ファイルが作られる。 # less /etc/logrotate.d/httpd /var/log/httpd/*log { missingok notifempty sharedscripts delaycompress postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript } logrotateはcronで実行されるようになっている。 # ls /etc/cron.daily logrotate このlogrotateの中身を確認すると #!/bin/sh /usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1 EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0 となっていて、以下の /etc/logrotate.conf の定義をもとにログをローテートしている。 # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation infor...