apahce httpd – matoken's blog https://matoken.org/blog Is there no plan B? Tue, 12 Jul 2022 14:15:29 +0000 ja hourly 1 https://wordpress.org/?v=6.9 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg apahce httpd – matoken's blog https://matoken.org/blog 32 32 Apache httpd 2.4でも503を返すようにする https://matoken.org/blog/2022/07/12/apache-httpd-2-4-return-503/ https://matoken.org/blog/2022/07/12/apache-httpd-2-4-return-503/#respond Tue, 12 Jul 2022 14:15:27 +0000 http://matoken.org/blog/?p=3715

自宅サーバが起動しなくなったのでLighttpdで全ページ503を返すようにしました.

思ったよりアクセスが多いのでアクセスの多いドメインのDNSを変更して外のサーバに向けることにしました.
このサーバはApache httpdが動いているのでLighttpdと同じ設定は使えないので少し調べて設定してみました.

対象ドメインの設定を作成.ここでは「 sub1.example.org 」としています.

`/etc/apache2/sites-enabled/090-sub1.example.org.conf
<VirtualHost *:80>
        ServerName sub1.example.org
        Redirect permanent / https://sub1.example.org/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName sub1.example.org
        ServerAdmin webmaster@example.org
        DocumentRoot /var/www/sub1.example.org/
        RedirectMatch 503 ^/(?!503\.html) (1)
        ErrorDocument 503 /503.html
        ErrorLog ${APACHE_LOG_DIR}/error_sub1.example.org.log
        CustomLog ${APACHE_LOG_DIR}/access_sub1.example.org.log combined
        SSLCertificateFile /etc/letsencrypt/live/sub1.example.org/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/sub1.example.org/privkey.pem
</VirtualHost>
</IfModule>
  1. すべてのURLを /503.html に転送します.

対象ドメインの証明書を旧サーバからコピーしておきます.

ディレクトリ作成
$ sudo mkdir -p /etc/letsencrypt/tmp/sub1.example.org/

リモートサーバの /etc/letsencrypt/live/sub1.example.org/fullchain.pem/etc/letsencrypt/live/sub1.example.org/privkey.pem/etc/letsencrypt/tmp/sub1.example.org/ 以下に置く.

権限設定してリンクを貼ります.
$ sudo chown -R root.ssl-cert /etc/letsencrypt
$ sudo ln -s /etc/letsencrypt/tmp/sub1.example.org/fullchain.pem /etc/letsencrypt/live/sub1.example.org/fullchain.pem
$ sudo ln -s /etc/letsencrypt/tmp/sub1.example.org/privkey.pem /etc/letsencrypt/live/sub1.example.org/privkey.pem

503用のhtmlを用意しておきます.

$ sudo -u www-data mkdir /var/www/sub1.example.org
$ sudo -u www-data vi /var/www/sub1.example.org/503.html

apache httpd再起動

$ sudo service apache2 restart

DNS書き換え前に検証の行えるローカルのPCのhosts書き換えて動作テスト.

$ echo "192.0.2.5 sub1.example.org" | sudo tee -a /etc/hosts (1)
$ w3m -dump_head head http://sub1.example.org/piyo | grep ^HTTP/ (2)
HTTP/1.1 503 Service Unavailable
$ w3m -dump_extra head http://sub1.example.org/piyo | lv (3)
  1. 新しいサーバのIPアドレスを指定する.
  2. 503が帰ってくることを確認
  3. 証明書も確認

動作確認が出来たら /etc/hosts を戻しておく.

この後,DNS書き換えを行いDNSが伝播してから再度動作確認を行う.

対象ドメインのSSL証明書更新もしておく.

$ sudo certbot certonly -d sub1.example.org

という感じでサーバ移行しました.
それまで自宅に9000アクセスほど有りましたが8500程は外のサーバに行くようになりました.

環境
$ dpkg-query -W apache2 certbot
apache2 2.4.38-3+deb10u7
certbot 0.31.0-1+deb10u1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/07/12/apache-httpd-2-4-return-503/feed/ 0
Nitterにrobots.txtを設定(Apache httpdのreverse proxy環境でAlias設定) https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/ https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/#comments Sun, 30 May 2021 22:39:20 +0000 http://matoken.org/blog/?p=3253

以前軽量TwitterフロントエンドのNitter をセルフホストしました.

最近アクセスが増えていて少しサーバが重くなったり自分が使うときに調子が悪かったりしています.クローラなんかが多いようなのでこれを robots.txt で拒否すると大分アクセスが減るのではと思い設定してみました.

まずは適当な robots.txtNitter の Root に置いてみましたが,対応していないようでアクセスできません.
Nitter の前段に置いてある Apache2 httpd でAlias を設定すればと思ってApache httpd のNitter の設定の VirtualHost の中に以下の設定を追加してみました.

/etc/apache2/sites-available/nitter.matoken.org.conf
        Alias /robots.txt /home/nitter/robots.txt
        <Location "/robots.txt">
                Require all granted
        </Location>

追加したあと設定を確認して設定を再読込します.

$ sudo a2ensite nitter.matoken.org.conf
$ sudo apache2ctl configtest
$ sudo systemctl reload apache2

しかしこの状態で /robots.txt にアクセスするとhttp ステータスコード 404 が帰ってきてアクセスできません.Proxy の方が優先のようです.

検索してみると以下のpageを見つけました. ProxyPass! を指定して指定したURLをProxy で無視するようにできるようです.

ということでこのように設定してみました.

        Alias /robots.txt /home/nitter/robots.txt
        <Location "/robots.txt">
                ProxyPass !
                Require all granted
        </Location>

再度設定チェックして再読込すると動作しました :)

$ w3m -dump_head https://nitter.matoken.org/robots.txt
HTTP/1.1 200 OK
Date: Sun, 30 May 2021 15:26:17 GMT
Server: Apache/2.4.38 (Debian) OpenSSL/1.1.1d
Last-Modified: Mon, 12 Apr 2021 23:19:53 GMT
ETag: "32c8-5bfcec03dd840-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 2938
Connection: close
Content-Type: text/plain

1日ほど待ってからアクセスの変化を見てみようと思います.

環境
$ dpkg-query -W apache2
apache2 2.4.38-3+deb10u4
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2021/05/31/set-robots-txt-in-nitter-alias-setting-in-reverse-proxy-environment-of-apache-httpd/feed/ 1
Debian stretch で php5 / php7.0 を切り替え https://matoken.org/blog/2018/09/14/switch-between-php-5-php-7-0-with-debian-stretch/ https://matoken.org/blog/2018/09/14/switch-between-php-5-php-7-0-with-debian-stretch/#respond Thu, 13 Sep 2018 21:34:26 +0000 http://matoken.org/blog/?p=2113

update-alternatives で OK かなと思ったのですが,

$ sudo update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status

--------------------

* 0            /usr/bin/php7.0   70        auto mode
  1            /usr/bin/php5     50        manual mode
  2            /usr/bin/php7.0   70        manual mode
  Press <enter> to keep the current choice[*], or type selection number: 0
$ php -v
PHP 7.0.30-0+deb9u1 (cli) (built: Jun 14 2018 13:50:25) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.30-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies

apache では php5 のままです.

$ w3m -dump http://localhost/phpinfo.php|grep -m1 'PHP Version'
PHP Version 5.6.30-0+deb8u1

apache module を切り替えたらokでした.

$ sudo a2dismod php5
$ sudo a2enmod php7.0
$ systemctl restart apache2
環境
$ dpkg-query -W apache2 php5 libapache2-mod-php5 php7.0 libapache2-mod-php7.0
apache2 2.4.25-3+deb9u5
libapache2-mod-php5     5.6.30+dfsg-0+deb8u1
libapache2-mod-php7.0   7.0.30-0+deb9u1
php5    5.6.30+dfsg-0+deb8u1
php7.0  7.0.30-0+deb9u1
$ lsb_release -d
Description:    Debian GNU/Linux 9.5 (stretch)
$ uname -m
x86_64
]]>
https://matoken.org/blog/2018/09/14/switch-between-php-5-php-7-0-with-debian-stretch/feed/ 0
apache httpd 2.4 で嵌まる https://matoken.org/blog/2015/06/29/apache-httpd-2-4/ https://matoken.org/blog/2015/06/29/apache-httpd-2-4/#respond Mon, 29 Jun 2015 12:06:31 +0000 http://matoken.org/blog/?p=833 DP1M0712

apahce httpd 2.2.(wheezy)から2.4.(jessie)への移行で適当なサーバをえいやで上げて動かなくなったのを復旧したメモ.

virtual host が有効にならない

/etc/apache2/sites-enabled/ 以下には設定ファイルがあるのに読み込まれず default しか表示されない.

sites-available からリンクを貼り直そうとするとエラーとなる

$ sudo a2dissite example.com
ERROR: Site example.com does not exist!
$ sudo rm /etc/apache2/sites-enabled/example.com
$ sudo a2ensite example.com
ERROR: Site example.com does not exist!

エラーメッセージで検索するとファイル名を *.conf にすれば良いよう.

この部分の該当場所は /etc/apache2/apache2.conf のここ

IncludeOptional sites-enabled/*.conf

2.2からの変更を確認するとこのように変わっていた.

 # Include the virtual host configurations:
-Include sites-enabled/
+IncludeOptional sites-enabled/*.conf

ということでこんな感じで

$ sudo rm /etc/apache2/sites-enabled/example.com
$ sudo mv /etc/apache2/sites-available/example.com /etc/apache2/sites-available/example.com.conf
$ sudo  a2ensite example.com.conf

設定ファイルの数が多かったら /etc/apache2/apache2.conf の設定を * にしても良いかも(未検証)

-IncludeOptional sites-enabled/*.conf
+IncludeOptional sites-enabled/*

403 が出る

エラーログは以下のような感じ.見慣れないエラー.

[authz_core:error] [pid 20566] [client nnn.nnn.nnn.nnn:49821] AH01630: client denied by server configuration: /var/www

以下のガイドを見るとどうもacl 周りのコマンド変更のようで

Order deny,allow
Deny from all

の代わりに

Require all granted

で動くようになった.


]]>
https://matoken.org/blog/2015/06/29/apache-httpd-2-4/feed/ 0