ステータス
ステータス確認
# service httpd status or # /etc/init.d/httpd status or # apachectl status
CentOS7・・・systemctl status httpd.service
起動
# service httpd start or # /etc/init.d/httpd start or # apachectl start
CentOS7・・・systemctl start httpd.service
自動起動
# chkconfig httpd on
CentOS7・・・systemctl enable httpd
停止
# service httpd stop or # /etc/init.d/httpd stop or # apachectl stop
CentOS7・・・systemctl stop httpd.service
再起動(強制的)
# service httpd restart or # /etc/init.d/httpd restart or # apachectl restart
CentOS7・・・systemctl restart httpd.service
再起動(切断しない)
# service httpd restart or # /etc/init.d/httpd restart or # apachectl restart
設定ファイル確認
# service httpd configtest or # /etc/init.d/httpd configtest or # apachectl configtest
conf設定 .htaccess設定
confファイルの場所
/etc/httpd/conf/httpd.conf
環境変数の指定
apache側で指定した変数をPHPなどのスクリプト言語で扱いたい場合
SetEnv DATABASE_NAME testdatabase
サイト引っ越し時の設定(301恒久的リダイレクト)旧サイト全ページ⇒新サイトTOP
RewriteRule ^/(.*) http://newsite.com [R=301,L]
サイト引っ越し時の設定(301恒久的リダイレクト)旧サイト全ページ⇒新サイト同階層ページ
RewriteRule ^/(.*)$ http://newsite.com/$1 [R=301,L]
httpからhttpsへの301恒久的リダイレクト
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
conf設定 mod_log_config
参考 https://httpd.apache.org/docs/2.2/ja/mod/mod_log_config.html#transferlog
LogFormatディレクティブ
ログの出力形式をテンプレートとして定義してテンプレートに名前をつける。テンプレートの定義だけでログは出力されない。
LogFormat "%v %h %l %u %t \"%r\" %>s %b" test_template
CustomLogディレクティブ
ログの出力形式と出力パスを定義してログを出力する。
CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"
LogFormatで定義したテンプレートを使用出来る。
CustomLog logs/access_log test_template
conf設定 mod_proxy リバースプロキシ
例
http://test.com/ をサーバA
http://test.com/bbb/ をサーバBにしたい場合の設定手順です。
https://normalblog.net/system/apache-reverse-proxy-mod_proxy/
conf設定 mod_rewrite
サンプル)httpだったらhttpsにする
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>
サンプル)httpだったらhttpsにするが、test.comの場合だけにする
ローカルではtest.localなどの場合で本番環境だけhttpsにしたい状況で、どちらでも対応出来る書き方をしたい場合。
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC] RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>
ログ(LOG)ファイル
ログファイル格納場所
/var/log/httpd/access_log /var/log/httpd/error_log
エラー
403 Forbidden[You don’t have permission to access / on this server.]
https://normalblog.net/system/13_permission-denied/
httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName
https://normalblog.net/system/error_servername/
モジュール
インストール済モジュール確認
# httpd -M