这是我的/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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试启动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
该/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 {
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
的HTTP指令只能在主背景下(即,不是内部的任何其他指示)它不能是内部另一个HTTP指令,因此在这个问题中描述的配置是一个致命的错误.删除重复的http指令会产生有效的配置,允许nginx启动.
| 归档时间: |
|
| 查看次数: |
6271 次 |
| 最近记录: |