さくらVPS【SSL】でNginx

さくらVPSでスタートアップスクリプト「CentOS_Let’s Encrypt」を使用してインストールされたNginxの設定

さくらVPSでスタートアップスクリプト「CentOS_Let’s Encrypt」を使用してCentOS7をインストールすると、ウェブサーバーはApacheでは無くNginx(エンジンエックス)がインストールされていました。

さくらVPSでSSHさくらVPSでFTPと同様にSSHとFTPの設定を行った後に、Nginxの設定を行いしました。

◎Web作成用ユーザーの設定

  • ユーザー(sakura)を追加しました。
    # useradd sakura
    # passwd sakura
    
  • sudoコマンドを有効にするため、ユーザー(sakura)をwheelグループに追加しました。
    # usermod -G wheel sakura
    # groups sakura
    sakura : sakura wheel
    
  • Web作成が出来るようにするため、ユーザー(sakura)をnginxグループに追加しました。
    # gpasswd -a sakura nginx
    # groups sakura
    sakura : sakura wheel nginx
    

◎Document rootフォルダの作成

  • Web公開用rootフォルダとして「/var/www/html」を作成しました。
    # cd /var
    # mkdir www
    # cd www
    # mkdir html
    
  • Web公開用rootフォルダの所有者をnginxに変更し、パーミッションを755に変更しました。
    # chown -R nginx:nginx /var/www/html
    # chmod 755 /var/www/html
    

◎Nginxの設定変更

  • 「/etc/nginx/conf.d/」以下にある「default.conf」と「https.conf」に記載されているWeb公開用rootフォルダ「/usr/share/nginx/html」を先に作成した「var/www/html」に変更しました。
    # cd /etc/nginx/conf.d/
    # cp default.conf default.conf.org (または https.conf)
    # nano default.conf (または https.conf)
    
    • 「default.conf」と「https.conf」の「location /」にあるrootの記述を「/var/www/html」に変更しました。
      location / {
          #root   /usr/share/nginx/html;
          root   /var/www/html;
          index  index.html index.htm;
      }
      
  • 上記修正後、Nginxのサービスを再起動しました。
    # systemctl restart nginx.service
    

◎Nginxの動作確認

  • テスト用の「index.html」を作成しました。
    # cd /var/www/html
    # nano index.html
    
    • 作成した「index.html」は以下となります。
      <html>
      <body>
      <h1>Welcome to Ngnix</h1>
      <p>vps.ohhappy.jp</p>
      </body>
      </html>
      
  • 「index.html」のパーミッションを「644」に変更しました。
    # chown nginx:nginx index.html 
    # chmod 644 index.html 
    
  • ブラウザで「http://(サーバーのURL)/」と「https://(サーバーのURL)/」にアクセスし、作成した「index.html」が「http:」と「https:」のどちらの場合も同じように表示されることを確認し、Nginxの動作確認を完了しました。
<= さくらVPS【SSL】でSSH | | さくらVPS【SSL】でPHP =>
スポンサーリンク
ohhappyをフォローする
Sakura.Oh!Happy.JP