Tomcatをnginx経由にする話
今回は前回(CentOS7でtomcat 8080ポートをこじ開ける話)までのtomcat 8080ポートで公開しているのをnginx経由に80ポートでアクセス出来る方法を検討しました。
まじめに、nginxをインストールします…
はい、パッケージはありませんのでリポジトリを追加します
公式ページでインストール方法があります。
https://nginx.org/en/linux_packages.html#RHEL-CentOS
手順はそのまま
/etc/yum.repos.d/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 module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
yum install nginx
入りました!
そ、し、て
起動と有効!(お約束)
systemctl enable nginx systemctl start nginx
80ポートにアクセすると、デフォルトページが表示されます…
このサイトにアクセスできません で接続が拒否されました。 次をお試しください 接続を確認する プロキシとファイアウォールを確認する ERR_CONNECTION_REFUSED
はいっ!SELinuxのため、接続拒否ですw
早速有効にします…
setsebool httpd_can_network_connect 1 -P
firewall-cmd --add-service=http --zone=public --permanent firewall-cmd --reload
# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s25 sources: services: dhcpv6-client http ssh tomcat ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
httpが追加!

アクセス出来ました!
次は簡単、/にアクセスされたらlocalhost:8080にアクセスします!
nginxの設定… defaultが要らないので、無効に…
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf_bk
そして、tomcatのリダイレクト用の設定をぶっ込みます
/etc/nginx/conf.d/tomcat.conf
server { listen 80; location / { proxy_pass http://localhost:8080; } }
… 最低限ですw
起動させます… `service nginx start
`
… 502 bad gatewayですね…
一度ログをチェックします
# tail /var/log/nginx/error.log 2020/12/09 22:24:30 [error] 3098#3098: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.11, server: , request: "GET / HTTP/1.1", upstream: "http://[::1]:8080/", host: "192.168.1.12" 2020/12/09 22:24:30 [warn] 3098#3098: *1 upstream server temporarily disabled while connecting to upstream, client: 192.168.1.11, server: , request: "GET / HTTP/1.1", upstream: "http://[::1]:8080/", host: "192.168.1.12" 2020/12/09 22:24:30 [error] 3098#3098: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.11, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "192.168.1.12" 2020/12/09 22:24:30 [warn] 3098#3098: *1 upstream server temporarily disabled while connecting to upstream, client: 192.168.1.11, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "192.168.1.12"
… tomcat動いていませんでした;;(結構時間かかりました)

404…とか思ったら、tomcatのルートはありません!
試験用に入れているPlantUMLにアクセスすると

やった〜!
これで世界平和になりました!
次回は初の生活系かなw
96%ネタですが…