1

I am following the tutorial on Flask serving with NGINX on Digital Ocean. After I created the following config file for NGINX in /etc/sites-available/mysite:

server {
    listen 80;
    server_name your_domain www.your_domain;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/user/myproject/myproject.sock;
    }
}

(obviously replaced domain to my domain and path to socket with my socket), when I run sudo nginx -t -c /etc/nginx/sites-available/mysite, I get

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-available/silaeder-projects:1 
nginx: configuration file /etc/nginx/sites-available/silaeder-projects test failed

I double-checked that I copied the code correctly. What could go wrong?

UPDATE:

If I run just sudo nginx -t, I do not get any errors, but sudo systemctl restart nginx fails with:

Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

The command systemctl status nginx.service returns:

 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-11-27 11:33:49 UTC; 39s ago
     Docs: man:nginx(8)
  Process: 8485 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 8475 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

journalctl -xe doesn't contain any time-relevant entries.

bathyscapher
  • 115
  • 4
sooobus
  • 113
  • 1
  • 5
  • 1
    The error is legit, because you only check the part of the config. Try to check with nginx -t only (nginx.conf has the base configuration). – patricks Nov 27 '18 at 10:14

2 Answers2

2

The nginx configuration file contains a http block which will include all files in /etc/nginx/sites-enabled/. The tutorial asks you to create the file in /etc/nginx/sites-available/ and then link to it from /etc/nginx/sites-enabled/.

Next it tells you to test the complete configuration using sudo nginx -t while you only test the configuration of your file. Your file however is only a small snippet of the complete nginx configuration required to make nginx work.

Make sure you create the softlink and then test without specifying a configuration file so it will test against the complete configuration file access from /etc/nginx.conf (or similar).

Paul
  • 3,037
  • 6
  • 27
  • 40
Tommiie
  • 5,627
  • 2
  • 12
  • 46
  • I followed the tutorial and created a lymlink; sudo nginx -t works fine: ~$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful – sooobus Nov 27 '18 at 11:16
  • But sudo systemctl restart nginx doesn't work: sudo systemctl restart nginx Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. – sooobus Nov 27 '18 at 11:17
  • 1
    And? Did you check the given commands for details? – Gerald Schneider Nov 27 '18 at 11:29
  • Sure, updated the question with more data. – sooobus Nov 27 '18 at 11:41
  • Finally resolved! – sooobus Nov 27 '18 at 11:56
0

The error is in a different file, the one that nginx read immediately prior to this one. Check the other files in sites-enabled for a missing }.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972