Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

GCEでNode.jsのサーバーサイドアプリを起動する最低限の設定

Last updated at Posted at 2018-11-18

Ubuntu 18 で GCE のインスタンスを作る

ssh でログインする


apt をアップデートする

sudo apt update

Nginx をインストール

sudo apt install nginx -y

nvm をインストール

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
source ~/.bashrc

Node.js をインストール

nvm install 10

GCP のサーバーアプリを使うための準備をする

gcloud auth login
gcloud auth application-default login
gcloud auth application-default print-access-token
echo export GOOGLE_CLOUD_PROJECT=PROJECT_ID >> ~/.bashrc
echo export GOOGLE_APPLICATION_CREDENTIALS=$HOME/.config/gcloud/application_default_credentials.json >> ~/.bashrc
source ~/.bashrc

Cloud Source Repository からソースコードをダウンロードする

mkdir csr
cd csr
git clone https://source.developers.google.com/p/PROJECT_ID/r/APP_NAME
cd APP_NAME

npm install をする

npm install && npm audit fix

Nginx の設定ファイルを変更し、 Node.js のサーバーアプリを外部に公開する

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default_copy
sudo nano /etc/nginx/sites-available/default
/etc/nginx/sites-available/default
location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404; # コメントアウト
                proxy_pass http://127.0.0.1:4000/; ## 追加(アプリが4000番ポートで起動する場合)
        }

Nginx を起動する

sudo service nginx start

Node.js サーバーアプリを起動する

npm start

(参考にしたもの https://qiita.com/yfujii01/items/41c15d885830deea8ed1 )


チューニング編は → NginxとOSカーネルの設定をチューニングしてパフォーマンスを上げる

0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?