状況
wsgi+Apache(httpd)でpythonのサービスを動かしたいが、エラーで動かない
ぐぐってもRed Hat系の情報が無い・古い
環境
- python 3.7
- mod-wsgiはpip3でインストール
# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.2 (Ootpa)
# httpd -v
Server version: Apache/2.4.37 (Red Hat Enterprise Linux)
エラー
tail /var/log/httpd/error_log
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 205: ordinal not in range(128)
ASCIIじゃないと怒られる。
スクリプトや設定ファイルはutf-8なので当たり前である
NG例
-
/etc/sysconfig/httpd
にHTTPD_LANG=ja_JP.utf8
を書く
そもそもファイルがない。
書いても読み込まれない。
-
/etc/rc.d/init.d/httpd
にexport LANG=ja_JP.utf8
を書く
そもそもファイルがない。
RedHatは7以降init.d系からsystemctl系に移行しているので、
古いバージョンを想定した上記方法では意味がない。(ここでだいぶ嵌った。。)
OKパターン
まずは起動設定を確認
# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
サービスファイルの場所が分かったので
vi /usr/lib/systemd/system/httpd.service
# Modifying this file in-place is not recommended, because changes
# will be overwritten during package upgrades. To customize the
# behaviour, run "systemctl edit httpd" to create an override unit.
# For example, to pass additional options (such as -D definitions) to
# the httpd binary at startup, create an override unit (as is done by
# systemctl edit) and enter the following:
# [Service]
# Environment=OPTIONS=-DMY_DEFINE
直接書くんじゃねー!ってことらしい(´・ω・`)
ので言われたとおりに
systemctl edit httpd
すると一時ファイルっぽいのが作られるので、
[service]
Environment=LANG='ja_JP.UTF-8'
保存して、systemctl restart httpd
サイトを再読み込みしてtail /var/log/httpd/error_log
PermissionError: [Errno 13] Permission denied:
まだエラー出てるけど、とりあえず文字コードはクリア!