0

I just started using Django and I try to deploy my project on the digital ocean server using Nginx. I am trying to set up SSL and domain (and they look good through the SSL checker and Google Dig DNS), however I get the 403 error in the browser once I try to access the webpage:

403 Forbidden nginx/1.14.0 (Ubuntu)

I have been trying different things with Nginx config but it does not seem to help, here is what I have now:

http {

...

 server {
                listen 443;
                ssl on;
                ssl_certificate /etc/ssl/server_merged_key.crt;
                ssl_certificate_key /etc/ssl/other_key.key;
                root /var/www/html;
                server_name domain.net www.domain.net ;
                location / {
                        root /var/www/html;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header X-Forwarded-Proto https;
                        proxy_set_header Host $http_host;
                        proxy_redirect off;
                }

...

}

The Django project is located on the home of the server with no directory (just two folders /mysite1/mysite/). The server starts fine.

I do not see any GET request on the server side once I see the 403 error on the page. I do see the 400 error You're accessing the development server over HTTPS, but it only supports HTTP., if I try to access through http://IP-IN-NUMBER:8000.

Also, the settings.py looks like this, if this relevant to the issue:

DEBUG = False

ALLOWED_HOSTS = ['IP-IN-NUMBERS','localhost', '127.0.0.1','HTTP_X_FORWARDED_PROTO', 'https','domain.net'
,'www.domain.net']

SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True 
SECURE_SSL_REDIRECT = True

How do I correctly set up Nginx for Django? Thank you so much for help!

starship
  • 53
  • 1
  • 6
  • Okay, so I edited root to /var/www/html but now I am getting 403 Forbidden error. I am not sure how to deal with that. I am editing the question correspondingly. – starship Aug 26 '21 at 22:16

1 Answers1

0

Okay, so I figured it out with additional help, I will put answer in case it will be helpful for others. Basically I just needed to put my Django files in the root of /var/www/html, so they could be together with the index file. This way Nginx allows to access this directory and not throw 403 error.

starship
  • 53
  • 1
  • 6