Ubuntuだと比較的楽にインストールできるそうだ。
最初にキーファイルをダウンロードする。
$ wget https://nginx.org/keys/nginx_signing.key
--2018-07-02 20:15:26-- https://nginx.org/keys/nginx_signing.key
nginx.org (nginx.org) をDNSに問いあわせています... 2606:7100:1:69::3f, 2001:1af8:4060:a004:21::e3, 206.251.255.63, ...
nginx.org (nginx.org)|2606:7100:1:69::3f|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1561 (1.5K) [text/plain]
`nginx_signing.key' に保存中
nginx_signing.key 100%[=================================================>] 1.52K --.-KB/s 時間 0s
2018-07-02 20:15:26 (105 MB/s) - `nginx_signing.key' へ保存完了 [1561/1561]
apt-keyでキーファイルを追加する。
$ sudo apt-key add nginx_signing.key
/etc/apt/sources.list.d/unit.listを作成する。
$ sudo vi /etc/apt/sources.list.d/unit.list
今回はUbuntu18.04を使っているので、次の内容を記載して保存する。
deb https://packages.nginx.org/unit/ubuntu/ bionic unit
deb-src https://packages.nginx.org/unit/ubuntu/ bionic unit
それじゃインストールを始めますか。
$ sudo apt update
$ sudo apt install unit
インストールが終わるとこんなメッセージが出る。
----------------------------------------------------------------------
Thank you for installing NGINX Unit!
Additional modules are available in standalone packages.
To see the available modules, run: apt search --names-only '^unit-'
Online documentation is available at https://unit.nginx.org/
----------------------------------------------------------------------
追加モジュールをインストールしろということなのな。
で、何を利用できるのか、追加モジュール一覧を表示させてみる。
$ apt search --names-only '^unit-'
ソート中... 完了
全文検索... 完了
unit-dbg/stable 1.2-1~bionic amd64
NGINX Unit (debug symbols)
unit-go1.10/stable 1.2-1~bionic all
Go 1.10 module for NGINX Unit
unit-go1.9/stable 1.2-1~bionic all
Go 1.9 module for NGINX Unit
unit-perl/stable 1.2-1~bionic amd64
Perl module for NGINX Unit
unit-perl-dbg/stable 1.2-1~bionic amd64
Perl module for NGINX Unit (debug symbols)
unit-php/stable 1.2-1~bionic amd64
PHP module for NGINX Unit
unit-php-dbg/stable 1.2-1~bionic amd64
PHP module for NGINX Unit (debug symbols)
unit-python2.7/stable 1.2-1~bionic amd64
Python 2.7 module for NGINX Unit
unit-python2.7-dbg/stable 1.2-1~bionic amd64
Python 2.7 module for NGINX Unit (debug symbols)
unit-python3.6/stable 1.2-1~bionic amd64
Python 3.6 module for NGINX Unit
unit-python3.6-dbg/stable 1.2-1~bionic amd64
Python 3.6 module for NGINX Unit (debug symbols)
unit-ruby/stable 1.2-1~bionic amd64
Ruby module for NGINX Unit
unit-ruby-dbg/stable 1.2-1~bionic amd64
Ruby module for NGINX Unit (debug symbols)
今回はPythonだから、次のコマンドで追加モジュールをインストールする。
$ sudo apt install unit-python3.6
インストールが終わるとこんなメッセージが表示される。
----------------------------------------------------------------------
The Python 3.6 module for NGINX Unit has been installed.
To check out the sample app, run these commands:
sudo service unit restart
sudo service unit loadconfig /usr/share/doc/unit-python3.6/examples/unit.config
curl http://localhost:8400/
Online documentation is available at https://unit.nginx.org
----------------------------------------------------------------------
いったんサーバをリブートしてみる。
$ sudo service unit restart
$ sudo service unit loadconfig /usr/share/doc/unit-python3.6/examples/unit.config
Loading configuration from /usr/share/doc/unit-python3.6/examples/unit.config...
{
"success": "Reconfiguration done."
}
$ curl http://localhost:8400/
2018-07-02 08:39:02 PM
Python: 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0]
ENV Variables:
LANG ja_JP.UTF-8
LANGUAGE ja_JP:ja
PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
INVOCATION_ID 11aa09ac823a44d2ab01da6ad6208da1
JOURNAL_STREAM 9:26162
DAEMON_ARGS --log /var/log/unit.log --pid /run/unit.pid
なんかよくわからないが、なんか動いているんだよね。
Nginx稼働に関する管理方法
大事なことだから転記しておく。
Nginxを停止する場合
$ sudo systemctl stop nginx
停止していたNginxを稼働させる場合
$ sudo systemctl start nginx
Nginxを再起動(一旦停止後再起動)させる場合
$ sudo systemctl restart nginx
Nginxの設定を変更した場合は、再起動させずに設定の反映が可能
$ sudo systemctl reload nginx
Nginxをサーバ起動時に自動的に稼働させたくない場合
$ sudo systemctl disable nginx
Nginxをサーバ起動時に自動的に稼働させたい場合
$ sudo systemctl enable nginx
Nginxを停止する場合
$ sudo systemctl stop nginx
停止していたNginxを稼働させる場合
$ sudo systemctl start nginx
Nginxを再起動(一旦停止後再起動)させる場合
$ sudo systemctl restart nginx
Nginxの設定を変更した場合は、再起動させずに設定の反映が可能
$ sudo systemctl reload nginx
Nginxをサーバ起動時に自動的に稼働させたくない場合
$ sudo systemctl disable nginx
Nginxをサーバ起動時に自動的に稼働させたい場合
$ sudo systemctl enable nginx
Ubuntu18にNginxをインストールする
参考にしたのはこちら。
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04
$ sudo apt update
$ sudo apt install nginx
シレっとインストール完了。
FireWallのステータスを確認する。
$ sudo ufw app list
利用可能なアプリケーション:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
Samba
で、Nginxのためにポートを開放する。
$ sudo ufw allow 'Nginx HTTP'
ルールを追加しました
ルールを追加しました (v6)
じゃ状況はどうなったか?
$ sudo ufw status
状態: アクティブ
To Action From
-- ------ ----
Nginx HTTP ALLOW Anywhere
Nginx HTTP (v6) ALLOW Anywhere (v6)
OK、OK。
もちろん上記には、差しさわりのあるポート開放情報は表示はさせていないよ。
Webサーバのステータスはどんな感じ?
$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-07-02 05:24:27 JST; 7min ago
Docs: man:nginx(8)
Process: 2360 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2348 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2361 (nginx)
Tasks: 5 (limit: 4370)
CGroup: /system.slice/nginx.service
├─2361 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─2364 nginx: worker process
├─2366 nginx: worker process
├─2368 nginx: worker process
└─2370 nginx: worker process
7月 02 05:24:27 niwatori systemd[1]: Starting A high performance web server and a reverse proxy server...
7月 02 05:24:27 niwatori systemd[1]: Started A high performance web server and a reverse proxy server.
動いてはいるが、プロセスを5つも立ち上げる必要はないな。
これはあとで調整しよう。
で、念のためにサーバをリブートして、ブラウザからhttp://IPアドレスと打ってどうなるか?
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
と表示されたら成功だ。
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04
$ sudo apt update
$ sudo apt install nginx
シレっとインストール完了。
FireWallのステータスを確認する。
$ sudo ufw app list
利用可能なアプリケーション:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
Samba
で、Nginxのためにポートを開放する。
$ sudo ufw allow 'Nginx HTTP'
ルールを追加しました
ルールを追加しました (v6)
じゃ状況はどうなったか?
$ sudo ufw status
状態: アクティブ
To Action From
-- ------ ----
Nginx HTTP ALLOW Anywhere
Nginx HTTP (v6) ALLOW Anywhere (v6)
OK、OK。
もちろん上記には、差しさわりのあるポート開放情報は表示はさせていないよ。
Webサーバのステータスはどんな感じ?
$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-07-02 05:24:27 JST; 7min ago
Docs: man:nginx(8)
Process: 2360 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2348 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2361 (nginx)
Tasks: 5 (limit: 4370)
CGroup: /system.slice/nginx.service
├─2361 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─2364 nginx: worker process
├─2366 nginx: worker process
├─2368 nginx: worker process
└─2370 nginx: worker process
7月 02 05:24:27 niwatori systemd[1]: Starting A high performance web server and a reverse proxy server...
7月 02 05:24:27 niwatori systemd[1]: Started A high performance web server and a reverse proxy server.
動いてはいるが、プロセスを5つも立ち上げる必要はないな。
これはあとで調整しよう。
で、念のためにサーバをリブートして、ブラウザからhttp://IPアドレスと打ってどうなるか?
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
と表示されたら成功だ。
登録:
投稿 (Atom)