Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 337
baconSoda Avatar asked Feb 11 '17 22:02

baconSoda


People also ask

What are the invalid server names in Nginx?

Other invalid names like “ -- ” and “ !@# ” may equally be used. nginx versions up to 0.6.25 supported the special name “ * ” which was erroneously interpreted to be a catch-all name. It never functioned as a catch-all or wildcard server name. Instead, it supplied the functionality that is now provided by the server_name_in_redirect directive.

Does Nginx test the name of a server?

If a server is the only server for a listen port, then nginx will not test server names at all (and will not build the hash tables for the listen port). However, there is one exception. If a server name is a regular expression with captures, then nginx has to execute the expression to get the captures. Compatibility

How do I use a special wildcard name in Nginx?

A special wildcard name in the form “ .example.org ” can be used to match both the exact name “ example.org ” and the wildcard name “ *.example.org ”. The regular expressions used by nginx are compatible with those used by the Perl programming language (PCRE).

What is an example of an invalid name?

The names “ www.*.example.org ” and “ w*.example.org ” are invalid. However, these names can be specified using regular expressions, for example, “ ~^www\..+\.example\.org$ ” and “ ~^w.*\.example\.org$ ”. An asterisk can match several name parts. The name “ *.example.org ” matches not only www.example.org but www.sub.example.org as well.


1 Answers

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

like image 141
Faisal Memon Avatar answered Oct 19 '22 22:10

Faisal Memon