ApacheでWebサーバー備忘録
Apacheとは
無料のWebサーバーソフトウェア。現在、最も世界でShareをとっている。
1995年から歴史が長く、安定性やサブ機能の豊富さ、他ソフトウェアとの互換性の良さで定評がある。
他のweb サーバーとしては、MicrosoftのIISやnginxがよく採用されている。
Apache Install
以下のWebsiteで.Zipファイルをダウンロードする。
C:直下などで展開して、Apache/conf/httpd.confを開いて、#ServerNameをコメントアウトを外して、ServerNameとする。
ServerName www.example.com:80
あとはC:Apache24binで以下のコマンドを実行して、Apache Webサービスを開始する。
C:Apache24\bin>httpd -k start
Apache起動端末なら、http://localhost/ で、その他の同ドメイン内端末なら http://192.168.**.***/ で、閲覧できる。
ブラウザ表示で"It works!"と出れば正常にアクセスできている。
Web page公開は適当にフォルダを作成し、C:Apache/conf/httpd.confを開いて以下の該当箇所のパスを修正する。
DocumentRoot "C:\xampp\webroot"
<Directory "C:\xampp\webroot">
公開フォルダの直下にhtmlファイルを置いて、先ほどと同様にhttp://localhost/ か http://192.168.**.***/ で開くと、web pageが表示される。※Apacheは再起動 C:\Apache24\bin>httpd -k restart
する必要がある。
公開フォルダの構造
webroot/
├─ index.html
├─ css/
├─ style.css
├─ img/
├─ sample.jpg
index.html
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>HTML Sample</title>
<link rel="stylesheet" href="css/style.css">
<!-- <script type="text/javascript" src="sample.js"></script> -->
</head>
<body>
<section class="wrapper">
<div class="container">
<div class="content">
<h2 class="heading">#######################</h2>
<div class="list">
<div class="list-item">######################################</div>
</div>
</div>
</div>
</section>
</body>
</html>
style.css
/* container */
.wrapper{
width:100%;
background-image:url(../img/sample.jpg);
background-repeat:no-repeat;
background-size:cover;
background-position: center center;
}
.wrapper .container{
max-width:1000px;
margin:0px auto;
padding:80px 0px;
}
/* content */
.wrapper .content .heading{
margin:0px 0px 40px 0px;
color:#ffffff;
font-size: 24px;
font-weight: normal;
text-align: center;
}
@media (min-width: 992px) {
.wrapper .content .list {
display: flex;
align-items: center;
justify-content: center;
}
}
.wrapper .content .list-item {
padding:30px;
line-height:1.8rem;
color:#ffffff;
text-align:center;
}
@media (min-width: 992px) {
.wrapper .content .list-item {
width:50%;
}
}
Apache module install
Apacheには豊富なmoduleがあり、以下のLinkで一覧が確認できる。非常に多くの"modle"が備わっています。
静的なモジュール(Install時に既に入っているもの)
デフォルトでは以下のモジュールが入っている。
C:\Apache24\bin>httpd -l
Compiled in modules:
core.c - 常に使用可能な Apache HTTP サーバのコア機能
mod_win32.c - 起動時や再起動時に実行コードとモジュールをサーバにロードする
mpm_winnt.c - Windows NT 向けに最適化されたマルチプロセッシングモジュール
http_core.c - 常に使用可能な Apache HTTP サーバのコア機能
mod_so.c - 起動時や再起動時に実行コードとモジュールをサーバにロードする
動的なモジュール(Install後に追加する必要があるもの)
C:\Apache24\bin>httpd -M
Loaded Modules:
actions_module (shared)
alias_module (shared)
allowmethods_module (shared)
asis_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
dir_module (shared)
env_module (shared)
include_module (shared)
isapi_module (shared)
log_config_module (shared)
mime_module (shared)
negotiation_module (shared)
setenvif_module (shared)
.....
まとめ
Apacheのinstallと簡単なweb siteを表示した。非常に簡単にWeb siteを立てられ、初心者でWeb siteに興味のある方は簡単にやってみるといいと思った。