Raspberry pi 4でapacheのリバースプロキシの設定

著者
Kato83
作成日
2020/05/05 - 19:54
更新日
2023/03/02 - 01:25

Raspberry pi 4にて、リバースプロキシをする際に地味に躓いたので、備忘録として共有。

要約としては、 proxy のモジュールが有効になっていなかっただけでした……

Rasberry pi 3bでもapacheでリバースプロキシを行っていたのですが、以下のような対応した記憶がないんですよね。寝ながら設定していたのかもしれない。

構成

ハード: Raspberry Pi 4 Model B OS: Raspbian Buster Lite Aapach2バージョン: 2.4.38 (Raspbian)

エラーが出たapacheの設定

<VirtualHost *:80>
        ServerName test.example.com
        ServerAdmin hoge@example.com
        ProxyRequests Off
        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
</VirtualHost>

上記の設定は http://localhost:8080 でローカルマシン内で動作しているサーバーを、apacheを用いて test.example.com でアクセスされたら、http://localhost:8080 を見るようにする設定です。

apacheを再起動しようとした際に出たエラー

root@raspberrypi:/home/pi# systemctl restart apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
root@raspberrypi:/home/pi# apache2ctl configtest
AH00526: Syntax error on line 25 of /etc/apache2/sites-enabled/pu10g.com.conf:
Invalid command 'ProxyRequests', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.

ProxyRequests で必要なモジュールがインクルードされていないと怒られているのがわかるかと思います。

対処法

root@raspberrypi:/home/pi# a2enmod proxy_http
Considering dependency proxy for proxy_http:
Enabling module proxy.
Enabling module proxy_http.
To activate the new configuration, you need to run:
  systemctl restart apache2

a2enmod proxy_httpproxy も依存関係にあるため、2つ同時に有効化されています。

これで再度apacheのコンフィグテストしたものが以下。

root@raspberrypi:/home/pi# apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

Syntax OKが出たので、あとはapacheを再起動してリバースプロキシの設定は完了です。

Category