nginxとspring boot連携(たぶん最小手順)

【環境】
OS:Amazon Linux2(Linux7 or CentoOS7 と同じ)

【前提】
自動起動(systemctl enable)の設定は省いている
・ローカル環境でEclipseなどでjarファイルを作成し、サーバに配備(/tmp/test.jar)


【手順】
1、nginxをインストール
  amazon-linux-extras install nginx1.12

  起動
  systemctl start nginx

  自動起動
  systemctl enable nginx.service

2、javaインストール
  yum install java-11-amazon-corretto

3、nginxとspring bootを連携
  // 以下に移動
  cd /etc/nginx
  // 赤字の個所のみ修正
  vim nginx.conf

   server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        #root         /usr/share/nginx/html;  ←ここ

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                proxy_pass http://localhost:8080/; ←ここ
        }


ポイント:rootはコメントで大丈夫!!

  // nginxの再起動
  systemctl restart nginx

4、spring bootの起動
  java -jar /tmp/test.jar

5、確認
  http://サーバのIP/


以上で完了です。