トップ 差分 一覧 ソース 置換 検索 ヘルプ PDF RSS ログイン

Apache(httpd)の設定

 /etc/httpd/conf

#ポート変更
Listen *:80

#SELinux の方でも制御しているので、80以外にするときは、SELinuxの設定も変える
# semanage port -a -t http_port_t -p tcp 88

#サーバーの名前
ServerName t-cent01

ServerName は、サーバ自身が使用するサーバ名とポート番号を指定します。このディレクティブは、Apache2からはデフォルトでコメントアウトされており、BIND でサーバー名が自動取得できるようになっていれば指定する必要はありませんが、起動時の問題を避けるためにも明示的に指定しておく事が推奨されています。

各ユーザのpublic_htmlの有効化(CentOS7)

/etc/httpd/conf.d/userdir.confを編集する
vi /etc/httpd/conf.d/userdir.conf

<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir disabled

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disabled" line above, and uncomment
    # the following line instead:
    # 
    UserDir public_html
</IfModule>

<Directory "/home/*/public_html">
    #AllowOverride FileInfo AuthConfig Limit Indexes
    AllowOverride FileInfo AuthConfig Limit Indexes Options
    #Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Options MultiViews SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>


各ユーザのpublic_htmlの有効化(CentOS7より前)

#各ユーザーの public_html を有効にする
<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir "disable"

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, use this directive instead of "UserDir disable":
    # 
    UserDir public_html

</IfModule>

# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
# ホームディレクトリのパーミッションも変更すること。
<Directory /home/*/public_html>
    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ExecCGI
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

インデックスファイル

DirectoryIndex index.html index.html.var index.php

CGIを使う場合

<Directory /home/*/public_html>
   AllowOverride FileInfo AuthConfig Limit Options
   Options MultiViews SymLinksIfOwnerMatch IncludesNoExec

AllowOverride All
Options All
は極力避ける。

.htaccess

Options +ExecCGI -Indexes
AddHandler cgi-script cgi pl

perl の実行権限は suExec によりホーム以下の場合は各ユーザの権限で実行される。
php での実行は、apache ユーザで実行されるので注意。
所有者をapacheにするか、sgid と apache の umask の設定で対処する

AddHandler cgi-script .cgi
または、 httpd.conf を
<Directory /home/*/public_html>
Options All
AllowOverride All
#AllowOverride FileInfo AuthConfig Limit
#Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
として、 .htaccess に
Options +ExecCGI
AddHandler cgi-script cgi pl
を書く。




 SSLを有効にする

Let's EncryptでSSL化
必要に応じてポートを変更する。
/etc/httpd/conf.d/ssl.conf 内の 443 を 変更先のポート番号へ変更。


 動作確認

test.cgi

#!/usr/bin/perl

print "Content-type:text/html\n\n";

print "<html>";
 print "<head>";
 print "<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=euc-jp\">";
 print "</head>";
print "テストCGIだよ";
print "</html>";

perl の実行権限は suExec によりホーム以下の場合は各ユーザの権限で実行される。

test.php

<? phpinfo() ?>

php での実行は、apache ユーザで実行されるので注意。
所有者をapacheにするか、sgid と apache の umask の設定で対処する

 Apache実行時の環境変数

/etc/sysconfig/httpd を編集することでApache実行時の環境変数を設定出来る

# vi  /etc/sysconfig/httpd

export NLS_LANG=Japanese_Japan.UTF8

とか

 Apacheのumaskを変更する

言語側でファイル書き込みの際にumaskを変更しても良い。
例えば、PHPの場合は

$oldmask = umask(002);
//何か処理
umask($oldmask)

Apacheのプロセスのumaskを変更するときは以下の方法を使う。

systemd

http://www.dondari.com/Apache%E3%83%A6%E3%83%BC%E3%82%B6%E3%81%AEumask%E5%80%A4%E3%82%92%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B-systemd%E7%B7%A8

/etc/systemd/system/httpd.service ファイルを作成します。

.include /lib/systemd/system/httpd.service
[Service]
UMask=002

systemdのリロード

systemctl --system daemon-reload

再起動

systemctl restart httpd

init.d(systemd以前)

http://www.dondari.com/index.php/Apache%E3%83%A6%E3%83%BC%E3%82%B6%E3%81%AEumask%E5%80%A4%E3%82%92%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B

/etc/sysconfig/httpd を編集することで、apacheユーザのumaskを変更できる。

#vi /etc/sysconfig/httpd

umask 002

# /etc/init.d/httpd restart


 Apacheのロケールを変更する

ApacheのロケールをUTF-8にしたい場合は、HTTPD_LANGをja_JP.UTF-8にする

/etc/sysconfig/httpd

#HTTPD_LANG=C
HTTPD_LANG=ja_JP.UTF-8

 任意のディレクトリを公開する

vi /etc/httpd/conf.d/hoge.conf

Alias /hoge /home/hoge/web
<Directory /home/hoge/web>
    #AllowOverride FileInfo AuthConfig Limit
    #Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      AllowOverride FileInfo AuthConfig Limit Options
   Options MultiViews SymLinksIfOwnerMatch IncludesNoExec
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

 アクセス制御

 2.4以降

全部拒否

Require all denied

全部許可

Require all granted

特定の接続元のみ拒否

<RequireAll>
Require all granted
Require not ip 192.168. 127.0.0.1
</RequireAll>

特定の接続元のみ許可

Require all denied
Require ip 192.168. 127.0.0.1

 2.2以前

全部拒否

Order deny,allow
Deny from all

全部許可

Order allow,deny
Allow from all

特定の接続元のみ拒否

order allow,deny
allow from all
deny from 192.168. 127.0.0.1

特定の接続元のみ許可

order deny,allow
deny from all
allow from 192.168. 127.0.0.1

 その他の設定

File does not exist: robots.txt/favicon.ico のエラーがログに出力される

favicon.icoが存在しないというエラーで、無視しても問題ない。
気になる場合は httpd.conf に以下を追記する。

Redirect 404 /favicon.ico

<Location /favicon.ico>
ErrorDocument 404 "No favicon
</Location>


[カテゴリ: OS > Linux]

[通知用URL]



  • Hatenaブックマークに追加
  • livedoorクリップに追加
  • del.icio.usに追加
  • FC2ブックマークに追加

最終更新時間:2018年01月13日 22時02分50秒