[Answered ]-SSL certificate incorrectly installed on nginx web server (Django web app)

2๐Ÿ‘

โœ…

I separated http/https part in my config example:

upstream myproject_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).
  # Check if the path to myproject.sock is correct!

  server unix:/home/myuser/myprojectfolder/myproject/myproject.sock; fail_timeout=0;
}


server {

    listen   80;
    server_name example.com;

    # define if needed
    #client_max_body_size 4G;

    charset utf-8;
    underscores_in_headers on;

    # write error log file for http errors:
    error_log /var/log/nginx/example-http-error_log info;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
        alias /home/myuser/myprojectfolder/myproject/;
    }

    location /media/ {
        alias /webapps/hello_django/media/;
    }

    location / {

        # we don't want nginx trying to do something clever with
        # redirects, we set the Host: header above already.
        proxy_redirect off;

        #proxy_pass_request_headers on;
        proxy_buffering on;
        proxy_buffers 8 24k;
        proxy_buffer_size 2k;

        # additional proxy parameters
        include proxy_params;

        # Try to serve static files from nginx, no point in making an
        # *application* server like Unicorn/Rainbows! serve static files.
        if (!-f $request_filename) {
            proxy_pass http://myproject_server;
            break;
        }
    }

    # Error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /home/myuser/myprojectfolder/myproject/templates/;
    }
}


server {

    listen 443 ssl;
    server_name example.com www.example.com;

    ssl_certificate /etc/ssl/certs/ssl-bundle.crt;
    ssl_certificate_key /etc/ssl/private/myserver.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    charset utf-8;
    underscores_in_headers on;

    location = /favicon.ico { access_log off; log_not_found off; }

    # write error log file for https errors:
    error_log /var/log/nginx/example-https-error_log info;

    location /static/ {
        alias /home/myuser/myprojectfolder/myproject/;
    }

    location /media/ {
        alias /webapps/hello_django/media/;
    }

    location / {

        # we don't want nginx trying to do something clever with
        # redirects, we set the Host: header above already.
        proxy_redirect off;

        #proxy_pass_request_headers on;
        proxy_buffering on;
        proxy_buffers 8 24k;
        proxy_buffer_size 2k;

        proxy_set_header X-Forwarded-Proto https;

        # additional proxy parameters
        include proxy_params;

        # Try to serve static files from nginx, no point in making an
        # *application* server like Unicorn/Rainbows! serve static files.
        if (!-f $request_filename) {
            proxy_pass http://myproject_server;
            break;
        }
    }

    # Error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /home/myuser/myprojectfolder/myproject/templates/;
    }
}

Comments in this config are from this source. I tried to adapt the settings you provided in your question. Please check if they are correct.

๐Ÿ‘คsemm0

Leave a comment