![]() |
| ◆ | apache のインストール |
|
[root@centos]# yum -y install httpd <--- 入力 |
|
| ◆ | apache の設定 |
|
[root@centos]# vi /etc/httpd/conf/httpd.conf <--- 入力 途中略 ### Section 1: Global Environment 途中略 ServerTokens OS <--- 書き換え(エラーページでOS名を表示しないようにする ) ↓ ServerTokens Prod 途中略 ## ## Server-Pool Size Regulation (MPM specific) ## 途中略 Listen 80 <--- 書き換え(通常は変更の必要はない ポートを指定する場合のみ変更) ↓ Listen 80 途中略 ### Section 2: 'Main' server configuration 途中略 ServerAdmin root@localhost <--- 書き換え(エラーページに表示される管理者のメールアドレスを指定) ↓ ServerAdmin xxxx@yyyy.zzz 途中略 #ServerName www.example.com:80 <--- コメント解除して書き換え(サーバー名を指定) ↓ ServerName www.papa-net.info:80 途中略 DocumentRoot "/var/www/html" <--- 書き換え(HPファイルを格納するフォルダーを指定) ↓ DocumentRoot "/home/user/www" 途中略 # # This should be changed to whatever you set DocumentRoot to. # <Directory "/var/www/html"> <--- 書き換え(HPファイルを格納するフォルダーを指定 **** はユーザー名) ↓ <Directory "/home/****/www"> 途中略 Options Indexes FollowSymLinks <--- 書き換え(index ファイルが無い場合フォルダ内を閲覧できないようにする) ↓ なお、CGIファイルを 任意の場所で起動したい場合は ExecCGI を追記 Options FollowSymLinks 途中略 DirectoryIndex index.html index.html.var <--- 追記(index.htm や index.php 等必要なものを追加する) ↓ DirectoryIndex index.html index.html.var index.htm index.php 途中略 ServerSignature On <--- 書き換え(エラーページで Apache のバージョンを表示しないようにする) ↓ ServerSignature Off 途中略 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" <--- 書き換え(CGIファイルを格納するフォルダを指定 ↓ CGIファイル格納フォルダを複数作る場合はコメント化) ScriptAlias /cgi-bin/ "/home/****/www/cgi-bin/" # # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin"> <--- 書き換え(CGIファイルを格納するフォルダーを指定 ↓ CGIファイル格納フォルダを複数作る場合は<Directory "/var/www/cgi-bin">〜</Directory>を追記 <Directory "/home/****/www/cgi-bin"> AllowOverride None Options None <--- 書き換え(CGIファイルを実行内容の指定<CGI・SSI・シンボリックの許可>) ↓ Options Includes ExecCGI FollowSymLinks Order allow,deny Allow from all </Directory> 途中略 AddLanguage ja .ja <--- 追記(AddLanguage ja .ja を 記述<文字化け対策>) AddLanguage ca .ca AddLanguage cs .cz .cs AddLanguage da .dk AddLanguage de .de AddLanguage el .el AddLanguage en .en AddLanguage eo .eo AddLanguage es .es AddLanguage et .et AddLanguage fr .fr AddLanguage he .he AddLanguage hr .hr AddLanguage it .it AddLanguage ja .ja <--- コメント化(文字化け対策) ↓ #AddLanguage ja .ja AddLanguage ko .ko AddLanguage ltz .ltz AddLanguage nl .nl AddLanguage nn .nn AddLanguage no .no AddLanguage pl .po AddLanguage pt .pt AddLanguage pt-BR .pt-br AddLanguage ru .ru AddLanguage sv .sv AddLanguage zh-CN .zh-cn AddLanguage zh-TW .zh-tw 途中略 LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW <--- 書き換え ↓ LanguagePriority ja en ca cs da de el eo es et fr he hr it ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW 途中略 AddDefaultCharset UTF-8 <--- コメント化(文字化け対策で文字コードのコメント化) ↓ #AddDefaultCharset UTF-8 途中略 #AddHandler cgi-script .cgi <--- コメント解除(CGIファイルを実行できるように指定< .pl 等を追加>) ↓ AddHandler cgi-script .cgi .pl 以下略 |
|
| ◆ | Apache の起動 |
|
[root@centos]# /etc/rc.d/init.d/httpd start <--- 入力 |
|
| Apache の自動起動設定 | |
|
[root@centos]# chkconfig httpd on <--- 入力 |
|
| 自動起動設定の確認 | |
|
[root@centos]# chkconfig --list httpd <--- 入力 httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off <--- 2・3・4・5 が on になっていればOK |
|
| ◆ | ホームページの表示確認 |
| ネットワーク内の他のパソコンのインターネットブラウザのアドレス欄にWebサーバーのアドレスを入力して下図のようなページが表示されればOK | |
|
|
|
| ◆ | ユーザー認証ページ |
|
ホームページにユーザー認証ページ(パスワードを入力しないと入れないページ)を追加 前提条件 : フォルダ=“pass” ユーザー名=“linuxuser” パスワード=“userpass” |
|
| ◆ | ユーザー認証用 apache の設定 |
|
[root@centos]# vi /etc/httpd/conf/httpd.conf <--- 入力 # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None <--- 書き換え ↓ AllowOverride All 最終行に以下を追記 <Directory /home/user/www/pass> <--- フォルダの指定 SSLRequireSSL (SSLでのアクセスのみを許可する場合に記述 尚、先にSSLサーバーを構築しないとエラーになります) AuthName "this directory is SelectUser Only" (ユーザー認証画面に表示されるメッセージ) AuthUserFile /etc/httpd/conf/.passwd (パスワードファイルの指定) AuthType Basic AuthGroupFile /dev/null Require valid-user </Directory> |
|
| ◆ | ユーザー認証ページ用フォルダの作成 |
|
[root@centos]# mkdir /home/xxxx/www/pass/ <--- 入力( フォルダ pass 作成) |
|
| ドキュメントルートの所有者変更 | |
|
[root@centos]# chown xxxx. /home/xxxx/www/pass/ <--- 入力(ドキュメントルートの所有者を xxxx に変更) |
|
| アクセス権を変更 | |
|
[root@centos]# chmod 755 /home/xxxx/www/pass/ <--- 入力 |
|
| ◆ | パスワードファイルの作成 |
| Apache の設定ファイルのある /etc/httpd/conf へ 移動 | |
|
[root@centos]# cd /etc/httpd/conf <--- 入力 |
|
| パスワード設定 | |
|
[root@centos conf]# htpasswd -c .passwd linuxuser <--- 入力(ユーザー linuxuser パスワードファイルの作成) New password: ******** <--- パスワード入力(* は実際には表示されません) Re-type new password: ******** <--- パスワード入力(* は実際には表示されません) Adding password for user linuxuser |
|
| なお、ユーザを追加したい場合は htpasswd .passwd
ユーザ名
(-c を付けない) 作成したパスワードファイル .passwd を Apache の動作権限で読み取れるように所有者情報を変更 |
|
|
[root@centos conf]# chown apache.apache .passwd <--- 入力(所有者情報を変更) |
|
| ◆ | apache を再読込 |
[root@centos]# /etc/rc.d/init.d/httpd reload <--- 入力 |
|
| ◆ | サブドメイン |
| 新しくサブドメイン用に /home/**** に www2 ディレクトリ作成 | |
|
[root@centos]# mkdir /home/****/www2 <--- 入力 |
|
| ドキュメントルートの所有者変更 | |
|
[root@centos]# chown xxxx. /home/****/www2/ <--- 入力(ドキュメントルートの所有者を xxxx に変更) |
|
| アクセス権を変更 | |
|
[root@centos]# chmod 755 /home/**** <--- 入力 [root@centos]# chmod 755 /home/****/www2 <--- 入力 |
|
| ◆ | サブドメイン用設定ファイルの作成 |
|
[root@centos]# vi /etc/httpd/conf.d/virtualhost.conf <--- 入力 (サブドメイン用設定ファイルの作成) 以下新規記述 NameVirtualHost *:80 <VirtualHost *:80> (現在のホスト) ServerName www.papa-net.info (現在のドメイン ) </VirtualHost> <VirtualHost *:80> (新しく追加するサブドメインホスト) ServerName ***.papa-net.info (新しく追加するドメイン名 ) DocumentRoot /home/****/www2 (ホームページファイルの保存場所) ErrorLog logs/****.papa-net.info-error_log (エラーログの保存場所) CustomLog logs/****.papa-net.info-access_log combined env=!no_log (アクセスログの保存場所) </VirtualHost> |
|
| サブドメインが別ホスト(別PC)にある場合は | |
|
[root@centos]# vi /etc/httpd/conf.d/virtualhost.conf <--- 入力 (サブドメイン用設定ファイルの作成) 以下新規記述 <VirtualHost *:80> (新しく追加するサブドメインホスト) ServerName ***.papa-net.info (新しく追加するドメイン名 ) ProxyPass / http://192.168.1.***:80/ (ホームページファイルの保存 されているPCのアドレス) </VirtualHost> |
|
| なお、別ホスト(PC)側でWebサーバーの設定がされている事が前提条件 | |
| ◆ | apache を再読込 |
[root@centos]# /etc/rc.d/init.d/httpd reload <--- 入力 |
|
| ◆ | バーチャルホスト |
| 新しくバーチャルホスト用に /home/**** に www3 ディレクトリ作成 | |
|
[root@centos]# mkdir /home/****/www3 <--- 入力 |
|
| ドキュメントルートの所有者変更 | |
|
[root@centos]# chown xxxx. /home/****/www3/ <--- 入力(ドキュメントルートの所有者を xxxx に変更) |
|
| アクセス権を変更 | |
|
[root@centos]# chmod 755 /home/**** <--- 入力 [root@centos]# chmod 755 /home/****/www3 <--- 入力 |
|
| ◆ | バーチャルホスト用設定ファイルの作成 |
|
[root@centos]# vi /etc/httpd/conf.d/virtualhost.conf <--- 入力 (サブドメイン用設定ファイルの作成) 以下新規記述 NameVirtualHost *:80 <VirtualHost *:80> (現在のホスト) ServerName www.papa-net.info (現在のドメイン ) </VirtualHost> <VirtualHost *:80> (新しく追加するバーチャルホスト) ServerName ***.****.com (新しく追加するバーチャルホスト名) DocumentRoot /home/****/www3 (ホームページファイルの保存場所) ErrorLog logs/***.****.com-error_log (エラーログの保存場所) CustomLog logs/***.****.com-access_log combined env=!no_log (アクセスログの保存場所) </VirtualHost> |
|
| ◆ | Apache の再読込 |
[root@centos]# /etc/rc.d/init.d/httpd reload <--- 入力 |
|