3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EC2にAngularJSアプリをデプロイした

Last updated at Posted at 2017-08-23

EC2のAmazon Linuxにproduction環境用のAngularJSアプリをデプロイしました。

まとまったものが見つからなくて結構ググったのでまとめておきます。

nvm&nodeのインストール

nvmで最新版のnodeをインストール。

> curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
> nvm ls-remote
...
v8.4.0
> nvm install v8.4.0
> nvm use v8.4.0

AngularJSアプリのビルド

AngularJSアプリをビルド。

> cd /path/to/app
> npm run ng build --prod

Nginx

AngularJSではトップページ以外のURLに対応するHTMLファイルは存在しないので、デフォルトの設定だとトップページ以外のURLにアクセスした時に404になってしまう。

なので、トップページ以外でもindex.htmlを返すように設定してNginxを起動。

/etc/nginx/conf.d/app.conf
server {
  listen 80;
  server_name _;
  resolver 8.8.8.8;
  root /path/to/app/dist;

  location / {
   try_files $uri /index.html;
  }
}
> sudo /etc/init.d/nginx start

あとはELBとつないだりして公開します。

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?