Am using following nginx conf file :
server {
listen 80;
server_name domain;
# Redirect HTTP to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/cert/ddomain.crt;
ssl_certificate_key /etc/nginx/cert/domain.key;
location / {
proxy_pass http://0.0.0.0:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
I am using the following docker file to run the container. This container runs 8000 port.
FROM python:3.8
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory in the container
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y
gcc
gettext
dbus
libdbus-1-dev
libcups2-dev
libcairo2-dev
libgirepository1.0-dev
libgtk-3-dev
libsecret-1-dev
pkg-config
wget
nginx
&& rm -rf /var/lib/apt/lists/*
# Copy the requirements file and install Python dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
# Copy SSL certificate files
COPY ssl_certificates/domain.crt /etc/nginx/cert/domain.crt
COPY ssl_certificates/domain.key /etc/nginx/cert/domain.key
# Copy the Nginx configuration file
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Copy the rest of the application files
COPY . /app/
# Expose port 8000 to allow communication to/from server
EXPOSE 8000
# Your application's command to run
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
When accessing the application using https://example.com:8080/. (8080 port is pointed server 8000 port) browser showing :
An error message like: “This site can’t provide a secure connection”
When am checking docker logs: “You’re accessing the development server over HTTPS, but it only supports HTTP.”
How can I enable HTTPS to my domain using a docker file and nginx?
Please help