reverse proxy が permission denied
概要
アプリを適当なポートで起動し、それに nginx で 80 番ポートからリバースプロキシでつなげるように設定するのが目標。
作業
アプリ立ち上げ
go の revel を使う。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo vi go/src/my-app/conf/app.conf | |
# Revel running behind proxy like nginx, haproxy, etc. | |
app.behind.proxy = true | |
# The IP address on which to listen. | |
http.addr = 127.0.0.1 | |
# The port on which to listen. | |
http.port = 9001 |
立ち上げ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
revel run my-app |
nginx 立ち上げ
リバースプロキシ用の設定。user を適切に設定しないとミスるかも。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo vim /etc/nginx/conf.d/my-app.conf | |
server { | |
listen 80; | |
location /my-app/ { | |
proxy_pass http://127.0.0.1:9001/; | |
} | |
} |
nginx スタート。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo systemctl start nginx |
selinux 設定
上記だと、 selinux で弾かれる。
log に弾かれたと出ていることを確認。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo grep denied /var/log/audit/audit.log | |
type=AVC msg=audit(1514890603.964:11538274): avc: denied { name_connect } | |
for pid=16608 comm="nginx" dest=9001 scontext=system_u:system_r:httpd_t:s | |
0 tcontext=system_u:object_r:tor_port_t:s0 tclass=tcp_socket |
9001 ポートへの http アクセスが拒否されているようなので、 80 と 9001 の selinux 上の状態を調べてみる。
いろいろ省略しているが、下記が見つかるので、 9001 を http_port_t に加える。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# semanage port -l | grep 80 | |
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000 | |
# semanage port -l | grep 9001 | |
tor_port_t tcp 6969, 9001, 9030, 9050, 9051, 9150 |
http_port_t に加える操作。 -a だと既に定義されていると言われてしまうので、 -m にする。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# semanage port -m -t http_port_t -p tcp 9001 |
これで動くはず。
まとめ
SELinux は毎回 disabled にしているので、そろそろちゃんとやろうと enforcing にして動かしてみますが複雑でこまりますね。
あと gist を試しに使ってみていますがやっぱり面倒…… blogger は markdown にするのにも stackeditとか使わないといけないようなので、なにか考えたい。
コメント
コメントを投稿