baconSoda
baconSoda

Reputation: 513

invalid parameter server_name in /etc/nginx/sites-enabled/django

I've deployed a Django application on DigitalOcean. First off, when i try to secure this with https and ssl, I get this error.

when i run nginx -t :

nginx: [emerg] invalid parameter "server_name" in /etc/nginx/sites-enabled/django:12

nginx: configuration file /etc/nginx/nginx.conf test failed

upstream app_server {
server unix:/home/django/gunicorn.socket fail_timeout=0;
}

server {
    #listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;

    listen 443 ssl
    server_name domain.com
    ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem
    ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
    root /usr/share/nginx/html;
    index index.html index.htm;

  client_max_body_size 4G;
  server_name _;

  keepalive_timeout 5;

  # Your Django project's media files - amend as required
  location /media  {
      alias path/to/media;
  }

  # your Django project's static files - amend as required
  location /static {
      alias path/to/static;
  }

  # Proxy the static assests for the Django Admin panel
  location /static/admin {
     alias path/to/staticadmin;
  }

location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_buffering off;

        proxy_pass http://app_server;
}


}

 server {
        listen 80;
       server_name domain.com;
       return 301 https://$host$request_uri;
 }

Furthermore, I can access the website using the ip address but not the domain name registered.It results in a 400 bad request page. Could this be an issue with the settings.py ?

for reference in settings.pyALLOWED_HOSTS=['*']. What list do I provide in the ip_addresses() function?

Are these two problems related?

using Django v1.10.5

Upvotes: 15

Views: 24211

Answers (1)

Faisal Memon
Faisal Memon

Reputation: 1107

You're missing semicolons on a bunch of lines, that's why nginx -t is failing.

Upvotes: 42

Related Questions