GNU/Linux >> Linux の 問題 >  >> Linux

Linux でソースから Nginx をインストールして構成する方法

nginx とは何かを理解する前に、nginx の発音方法を知っておく必要があります。

N G I N X ではありません。nginx は「エンジン X」と発音されます。

nginx は、「Engine X」から両方の e を削除した後の短縮形です。

nginx は、Apache に似たオープン ソースの Web サーバーですが、非常に軽量です。 nginx はウェブ サーバーとリバース プロキシ サーバーの両方です。

nginx の機能の一部を以下に示します。

  • 静的ファイルとインデックス ファイルを提供します
  • キャッシング付きリバース プロキシ
  • SSL をサポート
  • フォールト トレランスを備えたシンプルな負荷分散
  • 名前ベースと IP ベースの両方の仮想サーバーを構成できます
  • HTTP 基本認証
  • 書き換えモジュールをサポート
  • gzip、XSLT、SSI、画像サイズ変更フィルターをサポート
  • すべての主要なメール プロキシ サーバー機能がサポートされています
  • その他多数..

これは、nginx に関する現在進行中の一連の記事の一部です。

nginx をインストールして起動して実行することから始めましょう。所要時間はわずか 5 分です。

1. nginx をダウンロード

ここから nginx をダウンロードするか、以下に示すように wget を使用します。現在の安定版はnginx 1.0.5です

cd
wget http://nginx.org/download/nginx-1.0.5.tar.gz
tar xvfz nginx-1.0.5.tar.gz
cd nginx-1.0.5

2. nginx をインストール

./configure に渡すことができるオプションはたくさんあります。すべての構成オプションのリストを特定するには、次の手順を実行します。

./configure --help

以下は、自動的に有効になる http モジュールの一部です。それらを無効にする必要がある場合は、「–without-http_[module_name]」を ./configure オプションに渡す必要があります。たとえば、「proxy_module」を無効にするには、./configure –without-http_proxy_module を実行する必要があります。

  • charset_module – HTTP 文字セット モジュール
  • gzip_module – 圧縮用の HTTP gzip モジュール
  • ssi_module – サーバー側インクルード モジュール
  • auth_basic_module – HTTP 基本認証モジュール。
  • autoindex_module – 自動インデックス
  • rewrite_module – 書き換えルールをサポートする HTTP 書き換え
  • proxy_module – HTTP リバース プロキシ モジュール
  • fastcgi_module – fastcgi のサポート
  • memcached_module – nginx 用 Memcached モジュール
  • ..

以下は、自動的に有効にならない httpd モジュールの一部です。それらを有効にする必要がある場合は、「–with-http_[module_name]」を ./configure オプションに渡す必要があります。たとえば、nginx で SSL を有効にするには、「./configure –with-http_ssl_module」を実行する必要があります。

  • ssl_module – Secure Socket Layer (SSL) モジュールのサポート
  • xslt_module – XSLT (Extensible Stylesheet Language Transformations) モジュールのサポート
  • perl_module – Perl のサポート
  • ..

まず、以下に示すように ./configure を実行して、デフォルトの構成オプションで nginx をインストールします。

./configure
make
make install

./configure 中に、「./configure:エラー:HTTP 書き換えモジュールには PCRE ライブラリが必要です」というメッセージが表示される場合があります。 nginx http 書き換えモジュールに必要な PCRE ライブラリが見つからないというエラー メッセージ。

この問題を解決するには、Linux に「pcre」および「pcre-devel」パッケージをインストールするか、「./configure –without-http_rewrite_module」を実行して書き換えモジュールを無効にします

./configure の出力に示されているように、nginx は /usr/local/nginx の下にインストールされます。

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

3.デフォルトの nginx リッスン ポートを変更する

Nginx は、デフォルトでポート 80 をリッスンするように構成されています。これをテスト目的でマシンにインストールする場合、既に apache サーバーが実行されている場合は、nginx のリッスン ポートを変更する必要があります。

apache の httpd.conf ファイルと同様に、nginx には /usr/local/nginx/conf の下にある nginx.conf ファイルがあります。

nginx.conf のサーバー セクションで、ポート 80 を 8081 に変更します。

# vi /usr/local/nginx/conf/nginx.conf
    server {
        listen       8081;
        server_name  localhost;

4. Nginx サーバーを起動

nginx 実行可能ファイルは /usr/local/nginx/sbin ディレクトリにあります。この実行可能ファイルを呼び出すだけで、nginx サーバーを開始できます。

cd /usr/local/nginx/sbin
./nginx

これを開始すると、ps を実行すると、nginx の「マスター プロセス」と「ワーカー プロセス」が表示されます。

# ps -ef | grep -i nginx
root     18596 13:16 nginx: master process ./nginx
nobody   18597 13:16 nginx: worker process

nginx サーバーを起動した後、http://your-ip-address/ (または http://your-ip-address:8081、nginx.conf でリッスン ディレクティブを変更した場合) に移動すると、デフォルトが表示されます。 「nginx へようこそ!」と表示される nginx index.html

5. Nginx サーバーを停止

nginx サーバーを停止するには、次の手順を実行します。

cd /usr/local/nginx/sbin
./nginx -s stop

nginx の現在のバージョンを表示するには、次の手順を実行します。

# ./nginx -v
nginx: nginx version: nginx/1.0.5

問題をデバッグするには、/usr/local/nginx/logs にある error.log および access.log ファイルを表示します

# ls /usr/local/nginx/logs/
access.log
error.log
nginx.pid

Linux
  1. Linux に EMC PowerPath をインストールして構成する方法

  2. Linux でソース コードからソフトウェアをコンパイルしてインストールする方法

  3. Linux でソースから (および YUM を使用して) MongoDB をインストールする方法

  1. Linuxにソースからプログラムをインストールする方法

  2. Linuxでソースからソフトウェアをインストールする方法

  3. Linux にソースから TBB をインストールして動作させる方法

  1. UbuntuLinuxにMemcachedをインストールして構成する方法

  2. LinuxシステムにRedisをインストールして設定する方法

  3. Ubuntu20.04にスーパーバイザーをインストールして構成する方法