6

I recently tried to install LetsEncrypt certificate, but I couldn't start nginx again. when I run the command service nginx status.

I get this error message:

 nginx.service - A high performance web server and a reverse proxy server
 Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: 
enabled)
Active: failed (Result: exit-code) since Tue 2018-02-20 16:17:49 CET; 8min 
ago
Process: 1439 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; 
master_process on; (code=exited, status=1/FAILURE)

Feb 20 16:17:47 django-s-1vcpu-1gb-lon1-01 systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 nginx[1439]: nginx: [emerg] "location" directive is not allowed here in /etc/nginx/nginx.conf:87
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 nginx[1439]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: nginx.service: Control process exited, code=exited status=1
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: nginx.service: Unit entered failed 
Feb 20 16:17:49 django-s-1vcpu-1gb-lon1-01 systemd[1]: nginx.service: Failed with result 'exit-code'.

And here is /etc/nginx/sites-avalible/django:

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 nettside.no;
ssl_certificate /etc/letsencrypt/live/nettside.no/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nettside.no/privkey.pem;

root /usr/share/nginx/html;
index index.html index.htm;

client_max_body_size 4G;
server_name nettside.no;

keepalive_timeout 5;

# Your Django project's media files - amend as required
location /media  {
    alias /home/django/django_project/django_project/media;
}

# your Django project's static files - amend as required
location /static {
    alias /home/django/django_project/static;
}

# Proxy the static assests for the Django Admin panel
location /static/admin {
   alias /home/django/django_project/static/admin;

}

   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 nettside.no;
    return 301 https://$host$request_uri;
}
Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83
ranjith
  • 61
  • 1
    The error messages reads "location" directive is not allowed here in /etc/nginx/nginx.conf:87. There is a configuration error in the nginx.conf file on line 87. Please check yourself or paste nginx.conf here. – Bob Feb 22 '18 at 16:35
  • 1
    Thank you for answering. The problem was that i had a lovation i my nginx.conf file – ranjith Feb 22 '18 at 16:37
  • @Bob you might want to add your comment as an answer, so it can be accepted and voted on. – Phillip -Zyan K Lee- Stockmann May 02 '19 at 08:43

0 Answers0