1

I'm trying to set up a django project using SSL. I got it working without SSL but I'm clearly doing something wrong since https:// doesn't work and http:// just redirects to the main nginx site.

Here's my docker-compose file:

version: '3.2'

services:
  immweb:
    restart: always
    build: .
    command: gunicorn smn_imm.wsgi:application --bind 0.0.0.0:8000
    volumes:
        - /static:/static
        - /var/log/imm:/var/log/imm

  nginx:
    build: nginx
    depends_on:
      - immweb
    ports:
     - "80:80"
     - "443:443"
    volumes:
      - ./static/:/static/
      - /etc/nginx/:/etc/nginx/

Here's my nginx.conf

server {
    listen 80;
    server_name smn-imm;
}
server {

    listen 443;
    ssl on;
    server_name smn-imm;
    ssl_certificate      /etc/nginx/server.crt;
    ssl_certificate_key  /etc/nginx/server.key;

    location / {
        proxy_pass http://immweb:8000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        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_redirect off;
    }

    location /static/ {
    autoindex on;
    alias /static/;

    }    
}

Every site I look to for guidance does it a completely different way so I'm not sure what the "correct" way would be.

pnus
  • 33
  • 2
  • 7
  • Your nginx config serves nothing on port 80 so I expect you to get a 404, not a redirect. Did you clear your browser cache? Are you hitting some other web server entirely? You omitted part of your nginx configuration and it may be relevant. – Michael Hampton Apr 10 '19 at 00:43
  • @MichaelHampton Yes, browser cached was cleared and I'm not hitting any other servers. I should clarify that it doesn't redirect to nginx, but rather shows the "Welcome to nginx!" page that confirms that nginx is running on the server. As for the rest of the config, this is everything that's in the config file and the only nginx config in my docker container. – pnus Apr 10 '19 at 00:56
  • OK, but what happens with https? – Michael Hampton Apr 10 '19 at 01:03
  • @MichaelHampton https is met with a "Site can't be reached" message. – pnus Apr 10 '19 at 15:30
  • Try a different web browser which gives comprehensible error messages. – Michael Hampton Apr 10 '19 at 17:50

0 Answers0