2019-06-09に更新

Webサーバーを立てようぜ☆(^~^)?

読了目安:46分

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Webサーバーを立てようぜ☆?」

KIFUWARABE_80x100x8_01_Futu.gif
「 立てなくていいのに……☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 流行りの NginX をフロントエンドに、 NodeJS をバックエンドにしたやつを
立てましょう」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Team Viewer を使って 隣のPCにリモート・ログイン☆
Windows(10)の上で Linux(CentOS) を走らせて リモート・ログオフ☆
PuTTy で Linux にログインだぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 ややこしい……☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 まず NodeJS を走らすかだぜ☆
NodeJS は pm2 で走らせよう☆
コンソールウィンドウの横幅を贅沢に広げて……☆」

pm2 -h

pm2 list

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 あっ、なんにも動いてないぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 NodeJSはどこに入れた☆?」

clear

node -h

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 インストールはしてある☆」

node
> console.log("hello")
hello
undefined

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 NodeJS は生きているので走らせようぜ☆」

Node.jsで5行Webサーバを書いてみよう〈Node.jsシリーズ vol.1〉

KIFUWARABE_80x100x8_01_Futu.gif
「 そのWebアプリを以前 どこに置いた☆?」

sudo su -

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 スドゥー スゥー☆」

cd /
dir

cd var/local
dir

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 var(バー) の下には無いぜ☆」

cd /root
dir

cd /home
dir

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 どこ置いたんだろうな☆(^~^)?」

whereis node
node: /usr/bin/node /usr/share/man/man1/node.1.gz

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 何の役にも立たない情報だぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 リポジトリのディレクトリを決めておこうぜ☆?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 設定ファイルに何か書いてあるかも……☆?」

cd /etc
dir

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 NodeJSの設定ファイルは etc ディレクトリに無いぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 NodeJS の listenメソッドが書いた .jsファイルが どこかにあるだろ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 ダメだ進まん☆ 一旦 Windows10 で NodeJS のサーバーを構築し、
Linuxは ファイルを置くだけにしよう☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 Cドライブに置きましょう」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 [Windows]-[R], cmd でコンソール・ウィンドウ起動☆」

node -h
'node' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 NodeJS ってどこにインストールするものだぜ☆?」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 Cドライブ直下に node-js という名前のフォルダーを作りましょう」

NodeJS

node -h
'node' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

KIFUWARABE_80x100x8_01_Futu.gif
「 インストールしたのになぜ☆?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 コンソール・ウィンドウを閉じて もう一度 [Windows]-[R], cmd
よしいけた☆」

node
> console.log("hehehe")
hehehe
undefined

KIFUWARABE_80x100x8_01_Futu.gif
「 で、Webアプリ用のプログラムはどこだぜ☆?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 自力で書くか……☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 あっ、本番環境とテスト環境で 設定分けたいぜ めんどくせ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 Java Script なら JSON を使えばいいのでは……☆?」

Node.jsでJSONを読み込んで加工して書き出す

conf.json

{
    "port":80,
    "ip_address":"127.0.0.1"
}

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 こんな感じか☆」

start-server.js

const fs = require('fs');
const conf = JSON.parse(fs.readFileSync('./conf.json', 'utf8'));

var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello Kifuwarabe!\n');
}).listen(conf.port, conf.ip_address);

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 こんなんで動くのか☆?」

> cd c:\muzudho\node
> node start-server.js

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 返事がない☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 ブラウザで http://127.0.0.1:80/ にアクセスしろだぜ☆」

Hello Kifuwarabe!

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 動いてるぜ☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 Nginxも Windows10 に入れてみましょう」

Windows10環境にNginxをインストールする

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Nginx をダウンロードしたが、なんで こういうソフトって 設定ファイルと 実行ファイルを分けれるように
してくれないんだろな☆ 最小限の部分だけ バックアップ取りたいのに……☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 動かしてみましょう!」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 コマンド・プロンプトを右クリックして 管理者権限で実行☆」

cd C:\muzudho\nginx-1.16.0
start nginx.exe

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 ブラウザで localhost を見てみようぜ☆」

Hello Kifuwarabe!

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 これは NodeJS ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 お父ん、NodeJS を落とせだぜ☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 NodeJSを動かしているコンソール・ウィンドウで [Ctrl]+[C]、ブラウザを F5 リロード☆」

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.

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 おもしろ……☆ 同じポートを取り合ってたのかだぜ☆?」

KIFUWARABE_80x100x8_01_Futu.gif
「 先勝ちだろ☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 静的ファイルはNginxが、動的ファイルは NodeJS が担当するように
Nginx のリバース・プロキシ機能を利用して バックエンド・ノードに NodeJS を指定しましょう」

Nginx を Node.js のリバースプロキシとして使う

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Nginxの設定ファイルはどれだぜ☆? conf/nginx.conf だろうか☆?
コメントがいっぱい書いていて 読みにくいな……☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 コメントなんて全部消し飛ばせばいいのよ!」

nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 どこに upstream の設定を書けばいいんだぜ☆? 分からないときは 適当に書くか☆」

nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    # backend_node に LoopBack サーバー(localhost:3000)を追加
    upstream backend_node {
        ip_hash;
        server 127.0.0.1:3000;
    }

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;

            # 存在するファイルパスが指定された場合はそのまま Nginx で処理
            if ( -f $request_filename ) {
                break;
            }

            # 存在しないファイルパスが指定された場合は backend_node で処理
            if ( !-f $request_filename ) {
                proxy_pass http://backend_node;
                break;
            }
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 説明通りに書くと こうだが☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 NodeJSの方はポート 3000 で動くように変更しましょう。
Nginxの方は ポート80 のままで」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 NodeJSの conf.json のポート番号を 3000 に書き換えて コンソール・ウィンドウから再起動☆
Google chrome で localhost:80 では Nginx が、 localhost:3000 では NodeJS が動いている☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 準備はOKだな☆ Nginxを再起動しろだぜ☆」

nginx -s quit

localhost:80

このサイトにアクセスできません
start nginx.exe

localhost:80

Hello Kifuwarabe!

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 よし、バックエンド・ノードの NodeJS が優先されたぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 NodeJSが くたばってたら どうなるんだぜ☆?」

An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 エラー画面が出るみたいだな☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 今回作ったファイルを Linux に持っていって、同じことをしましょう」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 /home/muzudho/nodejs ディレクトリを作るぜ☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 PuTTy の pscp.exe を使ってファイル転送するの めんどくさい……☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 Windowsユーザーなら WinSCP 使うか☆?」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 FileZilla 使えないの?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 FileZillaで SFTP転送でけた……☆
IPアドレスを書き換えて……☆」

> node start-server.js
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use xxx.xxx.xxx.xxx:3000

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 あれっ、もう ポート3000使われてる?」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 localhost を確認してみましょう」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 curl 入ってたかな……☆?」

curl localhost:3000
<!DOCTYPE html><html><head><title>Express</title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>Express</h1><p>Welcome to Express</p></body></html>新しいメールが /var/spool/mail/root にあります

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 何かが先に動いている☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 NodeJS の Express だろ☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 だったら Nginx の conf/nginx.conf を設定すれば終わりかだぜ☆」

# cd /etc/nginx
# ls
# vi nginx.conf

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 中身がだいぶ違う☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 Nginxを入れ直せだぜ☆」

# nginx - v
nginx: invalid option: "v"

# nginx -V
nginx version: nginx/1.15.9
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 そんなに古くないが入れ直すか……☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 Nginxのローカルのリポジトリは前に どこかに作っただろ☆」

CentOS 7 (5, 6) で "安定版 (最新版)" のNginxをインストールする方法

# cd /etc/yum.repos.d/nginx.repo
-bash: cd: /etc/yum.repos.d/nginx.repo: ディレクトリではありません
新しいメールが /var/spool/mail/root にあります

# cd /etc/yum.repos.d
# dir
# vi nginx repo

"nginx" [New File]
:q!
# vi nginx.repo

nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 なんか前に色々書いてたんだな☆」

:q!
cd ~
sudo yum -y --enablerepo=nginx install nginx
読み込んだプラグイン:fastestmirror, langpacks
Repository nodesource is listed more than once in the configuration
Repository nodesource-source is listed more than once in the configuration


Error getting repository data for nginx, repository not found

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 読み込めないリポジトリが2つある☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 Nginxアンインストールできないの?」

Nginxのインストールとアンインストール (CentOS)

# service nginx stop
Redirecting to /bin/systemctl stop nginx.service
新しいメールが /var/spool/mail/root にあります

# chkconfig nginx off
情報:'systemctl disable nginx.service'へ転送しています。
Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service.

# yum remove nginx

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 なんか少しずつ 消されて行ってるぜ☆」

# yum remove nginx
読み込んだプラグイン:fastestmirror, langpacks
Repository nodesource is listed more than once in the configuration
Repository nodesource-source is listed more than once in the configuration
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ nginx.x86_64 1:1.15.9-1.el7_4.ngx を 削除
--> 依存性解決を終了しました。
base/7/x86_64                                                                                                                                                                                  | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                                                                                                           | 5.4 kB  00:00:00
epel/x86_64                                                                                                                                                                                    | 5.3 kB  00:00:00
epel/x86_64/updateinfo                                                                                                                                                                         | 977 kB  00:00:06
epel/x86_64/primary_db                                                                                                                                                                         | 6.7 MB  00:00:25
extras/7/x86_64                                                                                                                                                                                | 3.4 kB  00:00:00
extras/7/x86_64/primary_db                                                                                                                                                                     | 200 kB  00:00:01
nginx-mainline/7/x86_64                                                                                                                                                                        | 2.9 kB  00:00:00
nginx-mainline/7/x86_64/primary_db                                                                                                                                                             | 144 kB  00:00:24
nginx-stable/7/x86_64                                                                                                                                                                          | 2.9 kB  00:00:04
nginx-stable/7/x86_64/primary_db                                                                                                                                                               |  46 kB  00:00:06
nodesource/x86_64                                                                                                                                                                              | 2.5 kB  00:00:00
nodesource/x86_64/primary_db                                                                                                                                                                   |  60 kB  00:00:00
updates/7/x86_64                                                                                                                                                                               | 3.4 kB  00:00:00
updates/7/x86_64/primary_db                                                                                                                                                                    | 5.0 MB  00:00:09

依存性を解決しました

======================================================================================================================================================================================================================
 Package                                      アーキテクチャー                              バージョン                                                   リポジトリー                                            容量
======================================================================================================================================================================================================================
削除中:
 nginx                                        x86_64                                        1:1.15.9-1.el7_4.ngx                                         @nginx-mainline                                        2.7 M

トランザクションの要約
======================================================================================================================================================================================================================
削除  1 パッケージ

インストール容量: 2.7 M

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Zzz☆(^~^) 2時間ぐらい 眠ってしまった☆(^~^) おっ、消されているな☆」

上記の処理を行います。よろしいでしょうか? [y/N]

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 ええっ☆!」

y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  削除中                  : 1:nginx-1.15.9-1.el7_4.ngx.x86_64                                                                                                                                                     1/1
警告: /etc/nginx/nginx.conf は /etc/nginx/nginx.conf.rpmsave として保存されました。
警告: /etc/nginx/conf.d/default.conf は /etc/nginx/conf.d/default.conf.rpmsave として保存されました。
  検証中                  : 1:nginx-1.15.9-1.el7_4.ngx.x86_64                                                                                                                                                     1/1

削除しました:
  nginx.x86_64 1:1.15.9-1.el7_4.ngx

完了しました!
新しいメールが /var/spool/mail/root にあります

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 じゃあインストールしようぜ☆」

CentOS7 に nginx導入

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 とりあえずテキストファイル作成☆」

# sudo vi /etc/yum.repos.d/nginx.repo

nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 このファイルは消えてないのか☆ これ使えないのかだぜ☆?」

:wq

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 あ、上書き保存した☆ まあいいか……☆」

# sudo yum install nginx
読み込んだプラグイン:fastestmirror, langpacks
Repository nodesource is listed more than once in the configuration
Repository nodesource-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: ftp-srv2.kddilabs.jp
 * epel: ftp.yz.yamagata-u.ac.jp
 * extras: ftp-srv2.kddilabs.jp
 * updates: ftp-srv2.kddilabs.jp
nginx-mainline                                                                                                                                                                                 | 2.9 kB  00:00:00
nginx-stable                                                                                                                                                                                   | 2.9 kB  00:00:02
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ nginx.x86_64 1:1.17.0-1.el7.ngx を インストール
--> 依存性解決を終了しました。

依存性を解決しました

======================================================================================================================================================================================================================
 Package                                       アーキテクチャー                               バージョン                                                 リポジトリー                                            容量
======================================================================================================================================================================================================================
インストール中:
 nginx                                         x86_64                                         1:1.17.0-1.el7.ngx                                         nginx-mainline                                         767 k

トランザクションの要約
======================================================================================================================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 767 k
インストール容量: 2.7 M
Is this ok [y/d/N]:
y
Downloading packages:
nginx-1.17.0-1.el7.ngx.x86_64.rpm                                                                                                                                                              | 767 kB  00:00:47
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : 1:nginx-1.17.0-1.el7.ngx.x86_64                                                                                                                                                       1/1
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
  検証中                  : 1:nginx-1.17.0-1.el7.ngx.x86_64                                                                                                                                                       1/1

インストール:
  nginx.x86_64 1:1.17.0-1.el7.ngx

完了しました!
新しいメールが /var/spool/mail/root にあります
# nginx -V
nginx version: nginx/1.17.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 一応バージョン番号は上がった☆ メインライン(現行版)と同じだぜ☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 ステーブル(安定版)じゃなくていいの?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 もう入った☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 早よ起動しろだぜ☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Windows では start nginx.exe だったが、Linuxで .exe は無いだろう☆ 調べようぜ☆」

nginx起動、再起動

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 最近は service より systemctl の方が流行りじゃないかだぜ☆?」

# systemctl start nginx
新しいメールが /var/spool/mail/root にあります

# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Nginx 来たぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 状況を整理しよう☆
localhost:3000 では NodeJS/Express が、
localhost:80 では Nginx が動いているな☆?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 恐らく去年のわたしが動かしていた NodeJS/Express だけどな☆ NodeJSまでアンインストールするのはめんどくさい☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 Nginx のバックエンド・ノードに NodeJS を指定して、
localhost:80 から NodeJS/Express につながるようにしてくれだぜ☆」

201906blog1.jpg

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 今日の晩飯 こんなんだぜ☆ お前ら プログラマーになりたい☆?」

KIFUWARABE_80x100x8_01_Futu.gif
「 美味そうだな☆ それより nginx.conf を開けだぜ☆」

# cd /etc/nginx
# dir

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 あっ、めんどくせ☆ FileZilla 使おうぜ☆?」

KIFUWARABE_80x100x8_01_Futu.gif
「 まず中身確認☆」

# vi nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Windows版で見たのと違ってコメントが少ない……、というか変わってないのでは☆?」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 設定ファイル全部 Windows版で上書きしてしまいましょう」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 FileZilla では ユーザー・ホームディレクトリ以下しか見れない……☆」

# mv /home/muzudho/moving/nginx.conf /etc/nginx/nginx.conf
mv: `/etc/nginx/nginx.conf' を上書きしますか? y

# cat /etc/nginx/nginx.conf

nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

        # backend_node に LoopBack サーバー(localhost:3000)を追加
        upstream backend_node {
                ip_hash;
                server 127.0.0.1:3000;
        }

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;

                        # 存在するファイルパスが指定された場合はそのまま Nginx で処理
                        if ( -f $request_filename ) {
                                break;
                        }

                        # 存在しないファイルパスが指定された場合は backend_node で処理
                        if ( !-f $request_filename ) {
                                proxy_pass http://backend_node;
                                break;
                        }
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 設定はコピーでけた☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 curl で localhost:80 にアクセスしろだぜ☆」

# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Nginx が出てくるな☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 他の設定ファイルが 悪さをしているのでは?」

# cd /etc/nginx
新しいメールが /var/spool/mail/root にあります
# dir
conf.d  fastcgi_params  koi-utf  koi-win  mime.types  modules  nginx.conf  nginx.conf.rpmsave  scgi_params  uwsgi_params  win-utf

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 あれっ、 conf.d ってディレクトリだよな☆ 中に何かあるのか……☆」

# cd conf.d
# dir
default.conf  default.conf.rpmsave

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Windows版とフォルダー構成が違うのか☆(^~^)」

# vi default.conf

default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 サーバーを中に出したような感じをしている☆ 消すかだぜ☆(^~^)」

# rm default.conf
rm: 通常ファイル `default.conf' を削除しますか? y
# rm default.conf.rpmsave
rm: 通常ファイル `default.conf.rpmsave' を削除しますか? y

# curl localhost:80

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 変わりなし☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 設定ファイルを変更したら、サービスの再起動がいるのでは☆?」

# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
新しいメールが /var/spool/mail/root にあります
# systemctl stop nginx
# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
# systemctl status nginx.service
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 日 2019-06-09 20:02:13 JST; 38s ago
     Docs: http://nginx.org/en/docs/
  Process: 106799 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 106816 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
 Main PID: 106549 (code=exited, status=0/SUCCESS)

 6月 09 20:02:13 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
 6月 09 20:02:13 localhost.localdomain nginx[106816]: nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (13: Permission denied)
 6月 09 20:02:13 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
 6月 09 20:02:13 localhost.localdomain systemd[1]: Failed to start nginx - high performance web server.
 6月 09 20:02:13 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
 6月 09 20:02:13 localhost.localdomain systemd[1]: nginx.service failed.

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 nginx.conf の 13行目で パーミッション拒否 があるぜ☆」

keepalive_timeout  65;

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 13行目を消しても変わりなし☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 設定ファイルを全部作り直したらどうか☆?」

Biginner's guide

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 とりあえずコマンドを試す☆」

# nginx -s reload
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 サービスは止まってるのか☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 もしかして☆」

# ll

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 所有者が個人のものになってるぜ☆ root にしよ☆」

# chown root:root nginx.conf
# ll

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 それでも 起動できない☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 全部アンインストールしましょう」

# yum remove nginx

# find / -name nginx*
/etc/nginx/nginx.conf.rpmsave

# rm -rf /etc/nginx
# find / -name nginx*
/etc/yum.repos.d/nginx.repo
/var/lib/yum/repos/x86_64/7/nginx
/var/lib/yum/repos/x86_64/7/nginx-mainline
/var/lib/yum/repos/x86_64/7/nginx-stable
/var/log/nginx
/var/cache/yum/x86_64/7/nginx
/var/cache/yum/x86_64/7/nginx-mainline
/var/cache/yum/x86_64/7/nginx-stable
/var/cache/nginx
/usr/share/augeas/lenses/dist/nginx.aug
/usr/share/nginx

# rm /etc/yum.repos.d/nginx.repo
# rm -rf /var/lib/yum/repos/x86_64/7/nginx
# rm -rf /var/lib/yum/repos/x86_64/7/nginx-mainline
# rm -rf /var/lib/yum/repos/x86_64/7/nginx-stable
# rm -rf /var/log/nginx
# rm -rf /var/cache/yum/x86_64/7/nginx
# rm -rf /var/cache/yum/x86_64/7/nginx-mainline
# rm -rf /var/cache/yum/x86_64/7/nginx-stable
# rm -rf /var/cache/nginx
# rm -rf /usr/share/augeas/lenses/dist/nginx.aug
# rm -rf /usr/share/nginx

# find / -name nginx*

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 これでどうか☆?」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 yellowdog updater modified のリポジトリを作成しましょう」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 そんな名前だったな☆?」

# vi /etc/yum.repos.d/nginx.repo

nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 去年のわたしが書いた設定を また使おう☆ インターネット上の薄味な情報とか頼りない☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 gpg(証明書)のチェックなんか要るのかだぜ☆?」

# sudo yum install nginx

# nginx -V
nginx version: nginx/1.17.0

# cd /etc/nginx
# dir
conf.d  fastcgi_params  koi-utf  koi-win  mime.types  modules  nginx.conf  scgi_params  uwsgi_params  win-utf
# cat nginx.conf

nginx.conf


user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
# curl localhost:80
curl: (7) Failed connect to localhost:80; 接続を拒否されました

# systemctl start nginx
# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# curl localhost:3000
<!DOCTYPE html><html><head><title>Express</title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>Express</h1><p>Welcome to Express</p></body></html>

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 localhost:80 で Nginx が動いていて、 localhost:3000 で Nodejs/Express が動いているぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 設定ファイルを 早よ いじれだぜ☆」

# vi /etc/nginx/nginx.conf
i
-- INSERT --

nginx.conf


user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; # backend_node に LoopBack サーバー(localhost:3000)を追加 upstream backend_node { ip_hash; server 127.0.0.1:3000; } #gzip on; include /etc/nginx/conf.d/*.conf; }
# cd /etc/nginx/conf.d
# dir
default.conf
# vi default.conf

vi default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        # 存在するファイルパスが指定された場合はそのまま Nginx で処理
        if ( -f $request_filename ) {
            break;
        }

        # 存在しないファイルパスが指定された場合は backend_node で処理
        if ( !-f $request_filename ) {
            proxy_pass http://backend_node;
            break;
        }
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 いじった☆」

# systemctl reload nginx
# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>An error occurred.</h1>
<p>Sorry, the page you are looking for is currently unavailable.<br/>
Please try again later.</p>
<p>If you are the system administrator of this resource then you should check
the error log for details.</p>
<p><em>Faithfully yours, nginx.</em></p>
</body>
</html>

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 わらう☆ エラーが出た☆」

# curl http://127.0.0.1:80

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 同様☆」

# curl http://127.0.0.1:3000
<!DOCTYPE html><html><head><title>Express</title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>Express</h1><p>Welcome to Express</p></body></html>
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

KIFUWARABE_80x100x8_01_Futu.gif
「 エラーログを見てみようぜ☆」

# cat /var/log/nginx/error.log
2019/06/09 20:58:13 [crit] 108746#108746: *2 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "localhost"
2019/06/09 21:00:38 [crit] 108746#108746: *4 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "127.0.0.1"

KIFUWARABE_80x100x8_01_Futu.gif
「 ググると 似たようなのは これかだぜ☆」

nginx : Permission denied を解決
CentOS6.7 64bit SELinuxによるアクセス制御
[CENTOS7][NGINX] SELINUXを設定しホームディレクトリ配下のWEBコンテンツを公開を許可

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 SELinuxって何だぜ☆?」

# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted


KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 日本の記事には 手順が載っていて 理解の助けにならない☆
アメリカマンの記事を読もう☆ nginx selinux failed みたいなキーワードでググるぜ☆」

Using NGINX and NGINX Plus with SELinux

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 SELinux というのは Security-Enhanced Linux、セキュリティが強化されたリナックスのことで、
グーグル翻訳を使うと負けた気がするので 原文読む☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 負ければいいのに……☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 Linuxのパーミッションと言えば ディレクトリーやファイルに付いているが、
SELinux は プロセスにも アクセス権限を付けるもので、仕組みがでかそうだぜ☆」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 今の問題を解消する手順を暗記して さっさと進めましょう」

【ざっくりと理解する】SELinuxとは?
SELinux を使おう.使ってくれ.
CentOS7/RHEL7でむやみにSELinuxポリシー追加せずにnginx apacheをEnforcingのまま動かす

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 日本の記事は 英文を劣化コピー翻訳した ザル が多いので なるべく英語を読む☆ what is selinux

What is SELinux and how does it work?
SELinux Documentation
SELinux Project Wiki

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 以下のページが詳しげ☆」

AdminDocs

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 全部読んでると来月になってしまうので 触りながら進めてみよう☆
audit というのは 見張ってセキュリティ判定するものらしく、ログに残してくれているらしい☆」

# fgrep nginx /var/log/audit/audit.log

type=AVC msg=audit(1560081638.217:461459): avc:  denied  { name_connect } for  pid=108746 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1560081638.217:461459): arch=c000003e syscall=42 success=no exit=-13 a0=4 a1=55909ac1d2e8 a2=10 a3=7ffdf2a89140 items=0 ppid=108232 pid=108746 auid=4294967295 uid=996 gid=994 euid=996 suid=996 fsuid=996 egid=994 sgid=994 fsgid=994 tty=(none) ses=4294967295 comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 これ全部 SELinux がやっていることで☆、」

system_u:system_r:httpd_t:s0

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 みたいなやつは、システム・ユーザー(_u)のシステム・ロール(_r)のHTTPDタイプ(_t)の s0 レンジに照らし合わせて
拒否されたようで、rootユーザーでWebページを見ようとしている操作に パターン・マッチしたようだぜ☆」

KIFUWARABE_80x100x8_01_Futu.gif
「 で、どうするんだぜ☆?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 1つ1つ見ていく☆
nginx がどのようなパターンで監視されているか調べる☆
SELinux の用語としては、パターンではなく、ラベルと呼ぶようだぜ☆」

ps -eZ | grep nginx
system_u:system_r:httpd_t:s0    108232 ?        00:00:00 nginx
system_u:system_r:httpd_t:s0    108746 ?        00:00:00 nginx
新しいメールが /var/spool/mail/root にあります

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 nginx でのWebページへのアクセスは、 system_u:system_r:httpd_t:s0 ラベルが止めているようだぜ☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 次に NodeJS の index.html ページのラベルを調べたいが、どこに index.html あるんだろうな☆?」

KIFUWARABE_80x100x8_01_Futu.gif
「 検索しろだぜ☆」

# cd /
# find index.html
find: ‘index.html’: そのようなファイルやディレクトリはありません
# find index.htm
find: ‘index.htm’: そのようなファイルやディレクトリはありません
# cd /var/www
-bash: cd: /var/www: そのようなファイルやディレクトリはありません

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 NodeJS/Express が動的にページ生成してるとしたら、index.htmlファイルは無いわよ?」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 NodeJS ってどこにインストールされてるんだぜ☆?」

KIFUWARABE_80x100x8_01_Futu.gif
「 お父んがインストールしたんだろ、思い出せ☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 usr、share、local、webapps あっ、あった☆」

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 動的に生成されるページを、どうやってアクセス・コントロールするんだぜ☆?」

OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif
「 URLでコントロールするしかなくない?」

SELinuxで安心安全なnode.jsを目指していく
SELinux — Making it a Little Easier for Web

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 こんな設定してたら1年が経たないかだぜ☆?」

# getsebool -a | grep http
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_ipa --> off
httpd_run_preupgrade --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off
named_tcp_bind_http_port --> off
prosody_bind_http_port --> off
新しいメールが /var/spool/mail/root にあります

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 セキュリティを下げて、とりあえず ネットワークだけ許可するぜ☆」

# setsebool -P httpd_can_network_connect=1
新しいメールが /var/spool/mail/root にあります
# systemctl stop nginx
# systemctl start nginx
# curl localhost
<!DOCTYPE html><html><head><title>Express</title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>Express</h1><p>Welcome to Express</p></body></html>

KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif
「 いけた☆?」

ツイッターでシェア
みんなに共有、忘れないようにメモ

むずでょ

光速のアカウント凍結されちゃったんで……。ゲームプログラムを独習中なんだぜ☆電王戦IIに出た棋士もコンピューターもみんな好きだぜ☆▲(パソコン将棋)WCSC29一次予選36位、SDT5予選42位▲(パソコン囲碁)AI竜星戦予選16位

Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。

また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!

有料記事を販売できるようになりました!

こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?

コメント