I have a Docker container running my Ruby on Rails application, and the health check keeps failing because it returns an HTTP 301 instead of an HTTP 200. My app has been successfully deployed to AWS ECS as a service using Docker. However, when I check the healthcheck, it returns an HTTP 301 (
The HTTP 301 issue seems to be caused by HTTPS. What can I do to fix it so it returns an HTTP 200? When I manually visit the HTTPS healthcheck endpoint, it returns an HTTP 200.
Here is my Docker config in case it's helpful:
docker-compose.yml
version: '3'
services:
web:
build:
args:
DEPLOY_ENV_ARG: ${DEPLOY_ENV:-development}
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
Dockerfile
FROM ruby:2.7.2
SHELL ["/bin/bash", "-c"]
# development | test | production
ARG DEPLOY_ENV_ARG
ENV RAILS_ENV=${DEPLOY_ENV_ARG}
ENV NODE_ENV=${DEPLOY_ENV_ARG}
ENV APP_HOME=/myapp
LABEL app=myapp
LABEL environment=${DEPLOY_ENV_ARG}
RUN apt-get update
WORKDIR /
# Install dependencies
RUN apt-get install -y git nodejs
# For Redis
RUN apt-get install -y build-essential tcl
# Install NVM & Yarn
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get install -y nodejs
# Install yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update -qq \
&& apt-get install -y yarn
RUN mkdir -p ${APP_HOME} ${APP_HOME}/log
WORKDIR ${APP_HOME}
COPY . ${APP_HOME}
RUN gem install bundler && bundle install -j4 --with ${DEPLOY_ENV_ARG}
RUN yarn install
RUN bundle exec rails assets:precompile
EXPOSE 3000
CMD /bin/bash
RUN bundle exec rails s -b 0.0.0.0 -p 3000
CodePudding user response:
Your health check is configured to check the HTTP endpoint but since you have forced SSL in your Rails app, it is redirecting it to the HTTPS endpoint. This is what makes it to fail.
Since you are performing SSL offloading at the load balancer, your best option is to let the Load Balancer perform the HTTPS redirection and have your health check pointing to the HTTP endpoint. So you'll need to disable force SSL in your Rails app.