这就是/home/ubuntu/project/nginx.conf
的样子:
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;
}
}
}
当我尝试启动nginx时,它会抛出一个错误:"http" directive is not allowed here in /etc/nginx/sites-enabled/nginx.conf:1
我一直在阅读不同的帖子试图解决这个问题,但没有成功。我还提到如果我删除http { }
(因此只留下服务器定义),它就可以了。我做错了什么?
[编辑]忘了说这个,我建了一个链接:
sudo ln -s /home/ubuntu/project/nginx.conf /etc/nginx/sites-enabled/nginx.conf
答案 0 :(得分:5)
服务器上的/etc/nginx/nginx.conf
文件几乎肯定包含include sites-enabled/*;
include语句简单地将引用文件的内容内联(递归),因此nginx尝试启动时的结果配置将是:
# contents of /etc/nginx/nginx.conf
...
http {
...
# include sites-enabled/*;
# contents of /etc/nginx/sites-enabled/nginx.conf
http { # <----------------------
# configuration of the server
server {
...
}
}
}
http directive只能在主上下文中(即不在任何其他指令内),它不能在另一个http指令中,因此问题中描述的配置是致命错误。删除重复的http指令会产生有效的配置,允许nginx启动。
答案 1 :(得分:1)
请从nginx.conf中删除服务器块,并在sites-available文件夹中创建一个新文件。
此后,删除您创建的链接,并在sites-available文件夹中创建指向新创建文件的链接。
目前,请尝试删除链接并检查