0
1

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 1 year has passed since last update.

Nginxの導入でエラーが出たので、解決した。

Posted at

Nginx(エンジンエックス)とは、Webサーバーの一種です。ユーザーのリクエストに対して静的コンテンツのみ取り出し処理を行い、動的コンテンツの生成はアプリケーションサーバに依頼します。

Nginxの導入でエラーが出ました。
導入時のエラーから解決までを書いていきたいと思います。

Nginxの設定ファイルを編集しようの箇所で、espキーと:wqを入力して保存しようとすると、エラーが出ました。

まずEC2内ターミナルでNginxの導入をしました。

[ec2-user@ip-172-31-25-189 ~対象アプリのディレクトリ]$ sudo amazon-linux-extras install nginx1

次に、Nginx設定ファイルの設定です。
/etc/nginx/conf.d/rails.conf

upstream app_server {
  # Unicornと連携させるための設定
  server unix:/var/www/リポジトリ名/tmp/sockets/unicorn.sock;
}

# {}で囲った部分をブロックと呼ぶ。サーバの設定ができる
server {
  # このプログラムが接続を受け付けるポート番号
  listen 80;
  # 接続を受け付けるリクエストURL ここに書いていないURLではアクセスできない
  server_name Elastic IP;

  # クライアントからアップロードされてくるファイルの容量の上限を2ギガに設定。デフォルトは1メガなので大きめにしておく
  client_max_body_size 2g;

# 接続が来た際のrootディレクトリ
  root /var/www/リポジトリ名/public;

# assetsファイル(CSSやJavaScriptのファイルなど)にアクセスが来た際に適用される設定
  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;

  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app_server;
  }

  error_page 500 502 503 504 /500.html;
}

入力後に、escキー→:wqエンターキーで保存です。
しかし、ここでエラーが出て保存できませんでした。

エラーコードを読むと、

E45: 'readonly' option is set (add ! to override)

こう書いてました。多分これが原因です。

解決策として、オーバーライドするために

escキー ▶ :wq!

末尾に「!」を入力することで強制的に上書き保存が可能です。

これで解決しました。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?