【5%還元】Amazonキャッシュレスキャンペーン

【Cloud Run】PORT設定でエラー?![解決方法ログ]

web
【Cloud Run】PORT設定でエラー?![解決方法ログ]
Failed to start and then listen on the port defined by the PORT environment variable

「なぜ動かない!!」
「ENV port は default の 8080 にしたぞ?」

どうもー Goolge Cloud Run と死闘を繰り広げているガッチ(@gatchsite)です。

このガッチサイトは Google Platform 上で動かしているんですが。。。

以前、はてなブログのwwwありドメインで動かしていたため、wwwありwwwなしへリダイレクトさせようとハマったので、その解決方法です。

記事の内容はこちら

解決方法 WEB サーバーの listen を 8080 にする

やることはこれだけlisten 8080;追加しただけでした。

Cloud Run はデフォルトで 8080 ポートを使用する設定になっているようです。

ポートを合わせるだけという基礎的なエラーっにハマった自分がなんか恥ずかしいですが^^;

nginx の設定

せっかくなので、リダイレクトさせた nginx の設定も載せておきます。

server {
    listen       8080;
    server_name  www.gatch.site;

    location ^~ /entry/css-fadein-animation {
        return 301 https://gatch.site/css-fadein-animation;
    }
    location ^~ /entry/css-tab-sample {
        return 301 https://gatch.site/css-tab-sample;
    }
    location ^~ /entry/js-ajax-sample {
        return 301 https://gatch.site/js-ajax-sample;
    }
    location ^~ /entry/mysql8-initial-setting {
        return 301 https://gatch.site/mysql8-initial-setting;
    }
    location ^~ /entry/offscreen-lazyload {
        return 301 https://gatch.site/offscreen-lazyload;
    }
    location ^~ /entry/seo-internal-started {
        return 301 https://gatch.site/seo-internal-started;
    }
    location ^~ /entry/seo-internal-title {
        return 301 https://gatch.site/seo-internal-title;
    }
    return       301 https://gatch.site$request_uri;
}

Cloud Run PORT エラーのまとめ

Cloud Run は Docker を使用したコンテナ技術を使用しており、PORT やらネットワークやらの設定でハマることが多々あります。

Cloud Run のデフォルト PORT は 8080 というコトを覚えておくと良さそうです。

わからない部分があったら、ガッチまで遠慮なく連絡ください。

Twitter はこちら → @gatchsite

オススメプログラミングスクール
  • SkillHacks : Rubyを学びたい方。動画教材とLINE@による無制限サポート
  • TechAcademy : php/wordpressを学びたい方。現役エンジニアのマンツーマン
  • CodeCamp : Pythonを学びたい方。データサイエンス初級をオンラインで

Amazon キャッシュレス5%還元

関連の記事を読んでみる