这就是我的/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
The /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 {
...
}
}
}
我究竟做错了什么?
The http指令 http://nginx.org/en/docs/http/ngx_http_core_module.html#http只能位于主上下文中(即不在任何其他指令中),它不能位于另一个 http 指令中,因此问题中描述的配置是一个致命错误。删除重复的 http 指令会产生有效的配置,从而允许 nginx 启动。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)