Linuxにインストールする手順を紹介します。
普段はApacheを使用していますが、Webサーバ界ではNginxも利用シーンが多くてビックリしております。
※今回の手順はyumで実行します。
インストール環境
今回インストールするのは以下の環境です。
- CentOS:CentOS Linux release 7.4.1708 (Core)
- Nginx:nginx/1.12.2
インストール手順
コマンドは↓になります。
1 |
yum install nginx |
↓実施ログになります。★マークの箇所はすべてに「y」+「Enterキー」をしましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.fairway.ne.jp * epel: ftp.riken.jp * extras: mirror.fairway.ne.jp * ius: mirror.team-cymru.org * updates: mirror.fairway.ne.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ nginx.x86_64 1:1.12.2-1.el7 を インストール --> 依存性の処理をしています: nginx-all-modules = 1:1.12.2-1.el7 のパッケージ: 1:nginx-1.12.2-1.el7.x86_64 --> 依存性の処理をしています: nginx-filesystem = 1:1.12.2-1.el7 のパッケージ: 1:nginx-1.12.2-1.el7.x86_64 --> 依存性の処理をしています: nginx-filesystem のパッケージ: 1:nginx-1.12.2-1.el7.x86_64 --> トランザクションの確認を実行しています。 ---> パッケージ nginx-all-modules.noarch 1:1.12.2-1.el7 を インストール --> 依存性の処理をしています: nginx-mod-http-geoip = 1:1.12.2-1.el7 のパッケージ: 1:nginx-all-modules-1.12.2-1.el7.noarch --> 依存性の処理をしています: nginx-mod-http-image-filter = 1:1.12.2-1.el7 のパッケージ: 1:nginx-all-modules-1.12.2-1.el7.noarch --> 依存性の処理をしています: nginx-mod-http-perl = 1:1.12.2-1.el7 のパッケージ: 1:nginx-all-modules-1.12.2-1.el7.noarch --> 依存性の処理をしています: nginx-mod-http-xslt-filter = 1:1.12.2-1.el7 のパッケージ: 1:nginx-all-modules-1.12.2-1.el7.noarch --> 依存性の処理をしています: nginx-mod-mail = 1:1.12.2-1.el7 のパッケージ: 1:nginx-all-modules-1.12.2-1.el7.noarch --> 依存性の処理をしています: nginx-mod-stream = 1:1.12.2-1.el7 のパッケージ: 1:nginx-all-modules-1.12.2-1.el7.noarch ---> パッケージ nginx-filesystem.noarch 1:1.12.2-1.el7 を インストール --> トランザクションの確認を実行しています。 ---> パッケージ nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7 を インストール ---> パッケージ nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 を インストール ---> パッケージ nginx-mod-http-perl.x86_64 1:1.12.2-1.el7 を インストール ---> パッケージ nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7 を インストール ---> パッケージ nginx-mod-mail.x86_64 1:1.12.2-1.el7 を インストール ---> パッケージ nginx-mod-stream.x86_64 1:1.12.2-1.el7 を インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================== Package アーキテクチャー バージョン リポジトリー 容量 ============================================================================================================== インストール中: nginx x86_64 1:1.12.2-1.el7 epel 529 k 依存性関連でのインストールをします: nginx-all-modules noarch 1:1.12.2-1.el7 epel 16 k nginx-filesystem noarch 1:1.12.2-1.el7 epel 17 k nginx-mod-http-geoip x86_64 1:1.12.2-1.el7 epel 23 k nginx-mod-http-image-filter x86_64 1:1.12.2-1.el7 epel 26 k nginx-mod-http-perl x86_64 1:1.12.2-1.el7 epel 35 k nginx-mod-http-xslt-filter x86_64 1:1.12.2-1.el7 epel 25 k nginx-mod-mail x86_64 1:1.12.2-1.el7 epel 53 k nginx-mod-stream x86_64 1:1.12.2-1.el7 epel 76 k トランザクションの要約 ============================================================================================================== インストール 1 パッケージ (+8 個の依存関係のパッケージ) 総ダウンロード容量: 802 k インストール容量: 1.9 M Is this ok [y/d/N]: y ★←yを選択 Downloading packages: 警告: /var/cache/yum/x86_64/7/epel/packages/nginx-all-modules-1.12.2-1.el7.noarch.rpm: ヘッダー V3 RSA/SHA256 Signature、鍵 ID 352c64e5: NOKEY nginx-all-modules-1.12.2-1.el7.noarch.rpm の公開鍵がインストールされていません (1/9): nginx-all-modules-1.12.2-1.el7.noarch.rpm | 16 kB 00:00:00 (2/9): nginx-mod-http-perl-1.12.2-1.el7.x86_64.rpm | 35 kB 00:00:00 (3/9): nginx-mod-http-geoip-1.12.2-1.el7.x86_64.rpm | 23 kB 00:00:01 (4/9): nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64.rpm | 25 kB 00:00:00 nginx-mod-http-image-filter-1. FAILED 54 kB/s | 355 kB 00:00:02 ETA http://ftp.kddilabs.jp/Linux/packages/fedora/epel/7/x86_64/Packages/n/nginx-mod-http-image-filter-1.12.2-1.el7.x86_64.rpm: [Errno 14] HTTP Error 404 - Not Found 他のミラーを試します。 To address this issue please refer to the below knowledge base article https://access.redhat.com/articles/1320623 If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/ (5/9): nginx-mod-stream-1.12.2-1.el7.x86_64.rpm | 76 kB 00:00:01 (6/9): nginx-filesystem-1.12.2-1.el7.noarch.rpm | 17 kB 00:00:04 (7/9): nginx-mod-mail-1.12.2-1.el7.x86_64.rpm | 53 kB 00:00:03 (8/9): nginx-1.12.2-1.el7.x86_64.rpm | 529 kB 00:00:06 (9/9): nginx-mod-http-image-filter-1.12.2-1.el7.x86_64.rpm | 26 kB 00:00:04 -------------------------------------------------------------------------------------------------------------- 合計 109 kB/s | 802 kB 00:00:07 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 から鍵を取得中です。 Importing GPG key 0x352C64E5: Userid : "Fedora EPEL (7) <epel@fedoraproject.org>" Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5 Package : epel-release-7-9.noarch (@extras) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 上記の処理を行います。よろしいでしょうか? [y/N]y ★←yを選択 Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : 1:nginx-filesystem-1.12.2-1.el7.noarch 1/9 インストール中 : 1:nginx-mod-stream-1.12.2-1.el7.x86_64 2/9 インストール中 : 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64 3/9 インストール中 : 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64 4/9 インストール中 : 1:nginx-mod-http-perl-1.12.2-1.el7.x86_64 5/9 インストール中 : 1:nginx-mod-mail-1.12.2-1.el7.x86_64 6/9 インストール中 : 1:nginx-1.12.2-1.el7.x86_64 7/9 インストール中 : 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64 8/9 インストール中 : 1:nginx-all-modules-1.12.2-1.el7.noarch 9/9 検証中 : 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64 1/9 検証中 : 1:nginx-all-modules-1.12.2-1.el7.noarch 2/9 検証中 : 1:nginx-filesystem-1.12.2-1.el7.noarch 3/9 検証中 : 1:nginx-mod-stream-1.12.2-1.el7.x86_64 4/9 検証中 : 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64 5/9 検証中 : 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64 6/9 検証中 : 1:nginx-mod-http-perl-1.12.2-1.el7.x86_64 7/9 検証中 : 1:nginx-mod-mail-1.12.2-1.el7.x86_64 8/9 検証中 : 1:nginx-1.12.2-1.el7.x86_64 9/9 インストール: nginx.x86_64 1:1.12.2-1.el7 依存性関連をインストールしました: nginx-all-modules.noarch 1:1.12.2-1.el7 nginx-filesystem.noarch 1:1.12.2-1.el7 nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7 nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 nginx-mod-http-perl.x86_64 1:1.12.2-1.el7 nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7 nginx-mod-mail.x86_64 1:1.12.2-1.el7 nginx-mod-stream.x86_64 1:1.12.2-1.el7 完了しました! [root@centos7-local ~]# |
起動・停止方法
起動・停止やOS起動時の挙動設定をまとめました。
- 起動コマンド
1 |
systemctl start nginx.service |
- 停止コマンド
1 |
systemctl stop nginx.service |
- OS起動時の自動起動有効化
1 |
systemctl disable nginx.service |
- OS起動時の自動起動無効化
1 |
systemctl disable nginx.service |
インストール後の確認
まずはNginxと起動と自動起動設定を有効化しましょう。
1 2 |
systemctl srart firewalld systemctl disable firewalld |
↓が実施ログです。
1 2 3 4 |
[root@centos7-local ~]# systemctl start nginx.service [root@centos7-local ~]# systemctl enable nginx.service Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. [root@centos7-local ~]# |
Nginxを起動後、Webブラウザで「http://IPアドレス」と入力してアクセスしてみましょう。
私の環境はIPアドレスが192.168.56.101なので、「http://192.168.56.101/」となります。
下の画面が出力されればインストールが完了しました。
インストールしたがWebブラウザで繋がらない時は?
OSのセキュリティ設定によってはブラウザからアクセスできない場合があります。
そんな時はファイアウォールを無効化しましょう。
Centosの標準ファイアウォール「firewalld」を停止する手順は以下になります。
1 2 |
systemctl stop firewalld systemctl disable firewalld |
以下がファイアウォールの無効化実施ログです。
1 2 3 4 5 |
[root@centos7-local ~]# systemctl stop firewalld [root@centos7-local ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [root@centos7-local ~] |
posted with カエレバ
久保 達彦,道井 俊介 技術評論社 2016-01-16