Google Cloud Platform의 App Engine에서 nginx로 HTTPS 301 리디렉션하기
HTTP 요청을 쉽게 HTTPS로 전환하는 방법을 배울 수 있다. 이 튜토리얼 후에 AppEngine과 nginx가 원활하게 작동할 것이다.

요즘 Google Cloud Platform의 App Engine을 가지고 놀기 시작했다. Docker에서 PHP를 실행하기 위해 커스텀 런타임이 포함된 Flexible Environment를 사용 중이다. App Engine은 HTTP와 HTTPS를 통해 콘텐츠를 제공한다. Web UI를 통해 HTTP를 비활성화하거나 HTTP 트래픽을 HTTPS로 쉽게 리디렉션하는 것을 확인했지만, 현재로서는 불가능하다. 맞다, 기본 기능이 지원되지 않는다!
문서(https://cloud.google.com/appengine/docs/standard/php7/application-security)를 확인하고 app.yaml 파일을 통해 301 리디렉션을 설정하려고 했다. 시도한 내용은 다음과 같다:
handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
이번에는 nginx에 도전하기로 결정했다. nginx-app.conf 파일을 열고 다음과 같이 작성했다:
server_name _;
if ($http_x_forwarded_proto = “http”) {
return 301 https://$host$request_uri;
}
그리고 짜잔! 완벽하게 작동했다. 이 과정을 어떻게 시도하고 이해했는지 아래에서 확인할 수 있다.
~ curl -I http://ercan-ermis.ew.r.appspot.com/
HTTP/1.1 301 Moved Permanently
Date: Thu, 15 Apr 2021 07:03:34 GMT
Content-Type: text/html
Content-Length: 178
Server: nginx
Location: https://ercan-ermis.ew.r.appspot.com/
Via: 1.1 googleErcan의 다른 글
같은 저자, 다른 영역의 사이트 두 개.