先日、ConoHa VPS上にRedmineを構築したが、まだテスト用のWEBrickサーバーでしか確認できてないので、Apacheと連携させて、動くようにする。
1. Passengerのインストール
PassengerはRailsアプリを実行するためのApacheのモジュール。
gem install passenger
2. ApacheにPassengerモジュールをインストール
passenger-install-apache2-module
(略)
1. The Apache 2 module will be installed for you.
2. You'll learn how to configure Apache.
3. You'll learn how to deploy a Ruby on Rails application.
Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.
Press Enter to continue, or Ctrl-C to abort.
1 ### "1"を入力して[Enter]
--------------------------------------------
Which languages are you interested in?
Use to select.
If the menu doesn't display correctly, press '!'
‣ ⬢ Ruby
⬡ Python
⬡ Node.js
⬡ Meteor
### Ruby が選択されているのを確認して[Enter]
--------------------------------------------
(略)
Installation instructions for required software
* To install C++ compiler:
Please install it with yum install gcc-c++
* To install Curl development headers with SSL support:
Please install it with yum install libcurl-devel
* To install Apache 2 development headers:
Please install it with yum install httpd-devel
* To install Apache Portable Runtime (APR) development headers:
Please install it with yum install apr-devel
* To install Apache Portable Runtime Utility (APU) development headers:
Please install it with yum install apr-util-devel
sudo dnf install -y gcc-c++ libcurl-devel httpd-devel apr-devel apr-util-devel rpm-build
passenger-install-apache2-module ### 再度実行
(略)
c++: 致命的エラー: 強制終了 signal terminated program cc1plus
コンパイルを停止しました。
rake aborted!
Command failed with status (1): [c++ -o buildout/support-binaries/CoreMain.o -Isrc/agent -Isrc/cxx_supportlib -Isrc/cxx_supportlib/vendor-copy -Isrc/cxx_supportlib/vendor-modified -Isrc/cxx_supportlib/vendor-modified/libev -Isrc/cxx_supportlib/vendor-copy/libuv/include -Isrc/cxx_supportlib/vendor-copy/websocketpp -D_REENTRANT -I/usr/local/include -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long -Wno-missing-field-initializers -feliminate-unused-debug-symbols -feliminate-unused-debug-types -fvisibility=hidden -DVISIBILITY_ATTRIBUTE_SUPPORTED -DHAS_ALLOCA_H -DHAVE_ACCEPT4 -DHAS_SFENCE -DHAS_LFENCE -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -g -std=gnu++11 -Wno-unused-local-typedefs -Wno-format-nonliteral -DHAS_UNORDERED_MAP -c src/agent/Core/CoreMain.cpp]
Tasks: TOP => apache2 => buildout/support-binaries/PassengerAgent => buildout/support-binaries/CoreMain.o
(See full trace by running task with --trace)
しかし、”passenger-install-apache2-module”で、指示に従って不足パッケージをインストールしたものの、結局は長時間を要した末に、大量のワーニングは出るし、最終的には、ビルドが通らない事態に。
ただ、ダメ元でもう一回ビルドしたら、最後まで完了した。
メモリ1GBプランではメモリが足らんのだろうか?
bitnamiのDockerイメージで動かしてる現サイトもメモリ1GBプランなんだが・・・
・・・気になるところではあるが、一旦先に進もう。
3. Apacheの設定
3.1. モジュールの有効化
LoadModule文の記載内容は、”passenger-install-apache2-module”が通ると、最後の方で設定する内容が出力されているので、それを控えておく。
vi /etc/httpd/conf.modules.d/20-passenger.conf
LoadModule passenger_module /home/hoge/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.7/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/hoge/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.7
PassengerDefaultRuby /home/hoge/.rbenv/versions/2.6.6/bin/ruby
</IfModule>
3.2. バーチャルホストの設定
3.2.1. DNS設定
Redmine用に使いたいドメインのDNS設定を行なっておく。開設済ドメインの配下にディレクトリを置くだけなら不要。今回は「サブドメイン」にしたかったので、設定している。
3.2.2. SSL証明書
systemctl stop httpd
certbot certonly -n --standalone --agree-tos -d redmine.hogehoge.work -m your_mail@hogehoge.work --server https://acme-v02.api.letsencrypt.org/directory
3.2.3. httpd
sudo vi /etc/httpd/conf.d/redmine.hogehoge.work.conf
<Directory "/home/hogehoge/www">
DirectoryIndex index.html index.php
Require all granted
</Directory>
<VirtualHost *:80>
ServerName www.hogehoge.work
DocumentRoot /home/hogehoge/www
CustomLog logs/www.hogehoge.work_access.log combined
ErrorLog logs/www.hogehoge.work_error.log
# 常時SSL化
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
</VirtualHost>
<VirtualHost *:443>
ServerName www.hogehoge.work
DocumentRoot /home/hogehoge/www
CustomLog logs/www.hogehoge.work_access.log combined
ErrorLog logs/www.hogehoge.work_error.log
SSLCertificateFile /etc/letsencrypt/live/www.hogehoge.work/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.hogehoge.work/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/www.hogehoge.work/chain.pem
</VirtualHost>
ひとまず、これでApache経由でRedmine(Railsアプリ)を動作させ、ブラウザからhttpsのURLでアクセスすることができた。
タグ:
#CentOS Stream #ConoHa VPS #Rails #Redmine #Ruby