今日は、
取得したドメインを、Nginxで構築したWEBサーバーに紐付けて、
サイトを公開してしみました。
その際のメモ書きです。
今回は、「sampleuser」というユーザーを作成して、
「sample.com」というドメインでサイトを公開することにします。
環境は、お名前.comのVPS、OSはCeonOS6.5です。
事前にドメインのDNSを公開サーバーに設定しておく必要があります。
まずはユーザーを作成して、パスワードの設定です。
# useradd sampleuser
# passwd sampleuser
でパスワードを聞かれるので入力します。
ユーザー「sampleuser」のホームディレクトリが、「/home/sampleuser」という構造で作成されていると思います。
次に、WEBサイトの公開用ディレクトリ作成を作成してやります。
# mkdir -p /home/sampleuser/web/public
※ 今回は「/ホームディレクトリ/web/public」を公開ディレクトリとします。
公開ディレクトリの所有者も変更しておきます
# chown sampleuser /home/sampleuser/web/public
そして、
# vi /etc/nginx/conf.d/sampleuser.conf
として、
「/etc/nginx/conf.d/」直下に「sampleuser.conf」というconfファイルを作成し、
以下を記述します。
server { listen 80; server_name sample.com; charset UTF-8; access_log /var/log/nginx/sample.com.access.log main; location / { root /home/sampleuser/web/public; index index.html index.htm; try_files $uri $uri/ @rewrite; } }
nginxを再起動させます。
# service nginx restart
これでサイトの公開準備が整ったはず!!
ということで、
試しに「index.html」を作成してアクセスしてみます。
# vi /home/sampleuser/web/public/index.html
として、取り敢えず適当に「テスト」と記述しておきます。
※面倒なんで、取り敢えずタグは記述しません。
で、
サーバーに割り当てられているIPアドレスをブラウザから叩いてみると、
「403 Forbidden」になってしまいます。。。
ホームディレクトリのパーミッションの問題の可能性があるので、
変更することに。
# chmod 755 /home/sampleuser
もう一度アクセスしてみると、
困大は問題なくページが表示されました。
この記事へのコメントはありません。