This is how my /home/ubuntu/project/nginx.conf looks like:
http {
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name ec2-xxx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/project/media; # your Django project's media files - amend as required
}
location /static {
alias /home/ubuntu/project/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass unix:///home/ubuntu/project/deploy/web.sock;;
include /home/ubuntu/project/deploy/uwsgi_params;
}
}
}
When I try to start nginx, it throws me an error: "http" directive is not allowed here in /etc/nginx/sites-enabled/nginx.conf:1
I've been reading different posts trying to fix this but with no success. I also mention that If I remove http { } (so leaving only the server definition), it works. What am I doing wrong?
[EDIT] forgot to say this, I built a link:
sudo ln -s /home/ubuntu/project/nginx.conf /etc/nginx/sites-enabled/nginx.conf
The /etc/nginx/nginx.conf file on the server almost certainly contains include sites-enabled/*;
include statements simply put the contents of the referenced files inline (recursively) as such the resultant config when nginx tries to start will be along the lines of:
# contents of /etc/nginx/nginx.conf
...
http {
...
# include sites-enabled/*;
# contents of /etc/nginx/sites-enabled/nginx.conf
http { # <----------------------
# configuration of the server
server {
...
}
}
}
The http directive can only be in the main context (i.e. not inside any other directives) it cannot be inside another http directive hence the config described in the question is a fatal error. Removing the duplicate http directive results in a valid config, allowing nginx to start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With