LoginSignup
20

More than 5 years have passed since last update.

virtualbox(centos)でnginxインストールメモ

Posted at

環境 centos6.3(ゲストOS)macosx10.8(ホストOS)

nginxというapacheよりも高速に動くサーバーがにわか?に人気らしい
名前は知っていたがapacheでいいじゃん〜という怠けから今まで入れていなかったが気が向いたので入れてみた。

  • ここから先は全てrootユーザーで実行しています
  • 開発環境構築の話です。本番環境などはもっと詳しいブログをみつけてください。

参考にしたサイト

repoファイルの作成(リポジトリの追加)

nginxの公式方法のほうが最新のnginx入れられるのでこっちの方法をとった。
/etc/yum.repos.d/に追加する

vim /etc/yum.repos.d/nginx.repo



[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

インストール

yumでサクッと

yum install nginx

サーバーの設定

なんか間違えた場合に備えてバックアップ

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.default

サクッと書く。apacheの設定よりシンプル
listen,server_name,locationの項目のrootを変更するだけ

vim /etc/nginx/conf.d/default.conf


listen       80;
server_name  lo.test.org; #自分で設定しているhostのアドレス自分はlo.test.orgというhostを設定しているのでそれで設定

    location / {
        root   /home/web/lo.test.org/www; #追加apacheでいうドキュメントルートのこと自分の開発環境のドキュメントルートになおして記載してください
        index  index.html index.htm;
    }

hostsの設定について

知ってる人は読み飛ばしてください。
ゲストOS側(centos)のifconfigからゲストOS側のIPアドレス調べてホストOS(mac)側の/etc/hostsに記載する

ifconfig

#下記の項目(inet)がどこかにあるのでメモしておく(デフォルトだと192.168.xx.xxx)なはず
inet addr:192.168.56.101

ホストOS側(MAC)

vim /etc/hosts

#下記の項目を最後に記載
192.168.56.101  lo.test.org

apacheが動いている場合はapacheを止める

とりあえずはシンプルに動作確認するためにapacheは止める
(/etc/nginx/conf.d/default.confの設定でport80番を使用する設定にしている為)

/etc/init.d/httpd stop

テスト用のhtmlファイルを設置

いつもどおりのhello.worldを

vim /home/web/lo.test.org/www/index.html

<html>
<body>
hello.world
</body>
</html>

nginxの起動

これもapacheと似た感じでほぼ一緒

/etc/init.d/nginx start

動作確認

http://lo.test.orgにアクセスしてhello.worldが表示されればOK

nginxでググるとシンプルな設定方法がなかったので書いてみました。
これだけだと今時のナウなこと(php-fpmやnodejs等)はまだまだなのですがまずはnginxのインストールから慣れてからナウなことをしようかということで

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20