ApacheでWebサーバを作ろう!
ここでは、Apacheのインストール手順を掲載しています。
Apacheとは…?
Apacheはオープンソースで開発されているWebサーバ(HTTPサーバ)です。HTTPとはHyperText Transfer Protocolの略で、Webページで使われるHTMLや画像ファイルのデータ(コンテンツ)を送受信するためのルールのことです。
Apacheのインストール
[root@co ~]# yum -y install httpd
Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
base | 1.1 kB 00:00
extras | 2.1 kB 00:00
updates | 1.9 kB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.3-78.el5.centos set to be updated
base/filelists | 3.6 MB 00:01
extras/filelists_db | 241 kB 00:00
updates/filelists_db | 2.3 MB 00:00
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.2.3-78.el5.centos updates 1.3 M
Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 1.3 M
Downloading Packages:
httpd-2.2.3-78.el5.centos.x86_64.rpm | 1.3 MB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : httpd 1/1
Installed:
httpd.x86_64 0:2.2.3-78.el5.centos
Complete!
Apacheの設定
[root@co ~]# vi /etc/httpd/conf/httpd.conf
ServerTokens OS
↓
ServerTokens ProductOnly
ServerAdmin root@localhost
↓
ServerAdmin ************@gmail.com (管理者のメールアドレス)
#ServerName www.example.com:80
↓
ServerName kimamabi.mydns.jp:80 (取得したドメイン)
<Directory "/var/www/html">
Options Indexes FollowSymLinks
↓
Options Includes ExecCGI FollowSymLinks
AllowOverride None
↓
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<IfModule mod_userdir.c>
UserDir disable
↓
#UserDir disable
#UserDir public_html
↓
UserDir public_html
</IfModule>
#<Directory /home/*/public_html>
# AllowOverride FileInfo AuthConfig Limit
# Options MultiViews Indexes 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>
↓
<Directory /home/*/public_html>
AllowOverride All
Options Includes ExecCGI FollowSymLinks
<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
↓
DirectoryIndex index.html index.htm index.php index.cgi index.shtml
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog logs/access_log combined
↓
CustomLog logs/access_log combined env=!no_log
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Request_URI "xmlrpc\.php" no_log
SetEnvIf Request_URI "zero_vote" no_log
SetEnvIf Request_URI "sumthin" no_log
SetEnvIf Request_URI "~akirin" no_log
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(css)$" no_log
#LANのネットワークアドレスを指定
SetEnvIf Remote_Addr 192.168. no_log
ServerSignature On
↓
ServerSignature Off
<Directory "/var/www/icons">
Options Indexes MultiViews
↓
Options MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
↓
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
#AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl
コンテンツの圧縮転送
コンテンツを転送するときに、サーバ側で圧縮して転送する"mod_deflate"というモジュールもがあります。
以下のように入力をすることで、設定された形式のファイルに対し圧縮転送を行うことが出来ます。
[root@co ~]# vi /etc/httpd/conf.d/deflate.conf
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png|ico|z|taz|t?gz|t?bz2?|zip|lzh|sit|rar|pdf|mp3|ogg|wma|rm|wmv|mov|mpe?g)$ \no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
[root@co ~]# yum -y install mod_ssl
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
base | 1.1 kB 00:00
extras | 2.1 kB 00:00
updates | 1.9 kB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mod_ssl.x86_64 1:2.2.3-78.el5.centos set to be updated
--> Processing Dependency: libdistcache.so.1()(64bit) for package: mod_ssl
--> Processing Dependency: libnal.so.1()(64bit) for package: mod_ssl
--> Running transaction check
---> Package distcache.x86_64 0:1.4.5-14.1 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mod_ssl x86_64 1:2.2.3-78.el5.centos updates 97 k
Installing for dependencies:
distcache x86_64 1.4.5-14.1 base 121 k
Transaction Summary
================================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 218 k
Downloading Packages:
(1/2): mod_ssl-2.2.3-78.el5.centos.x86_64.rpm | 97 kB 00:00
(2/2): distcache-1.4.5-14.1.x86_64.rpm | 121 kB 00:00
--------------------------------------------------------------------------------
Total 986 kB/s | 218 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : distcache 1/2
Installing : mod_ssl 2/2
Installed:
mod_ssl.x86_64 1:2.2.3-78.el5.centos
Dependency Installed:
distcache.x86_64 0:1.4.5-14.1
Complete!
暗号化モジュールがインストールできたら、設定を行います。
[root@co ~]# vi /etc/httpd/conf.d/ssl.conf
#DocumentRoot "/var/www/html"
↓
DocumentRoot "/var/www/html"
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
↓
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
↓
SSLCertificateKeyFile /etc/pki/tls/certs/server.key
更に、設定ファイルの最後尾に以下を追記します。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog "logs/rewrite_log"
RewriteLogLevel 0
RewriteCond %{HTTP_HOST} !kimamabi.mydns.jp$
RewriteRule ^/(.*)?$ http://%{HTTP_HOST}/$1 [L,R]
</IfModule>
</VirtualHost>
暗号化通信を行いたいディレクトリを変更する場合は"DocumentRoot"の設定を変更してください。
上の設定では、/var/www/html内のファイルに対し、HTTPS通信を行うようになります。
Perlへのシンボリックリンクの作成
CentOSでのPerlの実行場所は/usr/bin/perlとなっています。
しかし、CGIによっては/usr/local/bin/perlを実行場所にしているものがあるので、それに対応するため、シンボリックリンクを張ります。
[root@co ~]# ln -s /usr/bin/perl /usr/local/bin/perl
[root@co ~]# whereis perl
perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz
PHPの設定へと続きます。
PHPへ
今回新しく登場したコマンド
- ln
- whereis
[広告]

トップページ
Rocky Linux 8
CentOS 7
Scientific Linux 6
CentOS 5
○準備
○VMware Player
○Hyper-V(Win Proのみ)
○導入
○セキュリティ対策
○Dynamic DNS
○NTPサーバ
○データベース
○WEBサーバ
○FTPサーバ
○メールサーバ
○DNSサーバ
○ファイルサーバ
○ブログシステム
○その他
ブログ
[広告]