我开始,我想使用nginx连接到我的数据库。这是我的sites-enables / default
文件:
http {
upstream database {
postgres_server 192.168.0.166 dbname=stardb
user=username password=yourpass;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location /ip {
postgres_pass database;
postgres_query HEAD GET "SELECT http_host as ip FROM establishment_view where aet = 'NXS_DEV_FLO2'";
}
}
}
我得到此错误:
nginx [7597]:nginx:[empry]" http"指令在此处不允许在/etc/etc/nginx/stites-enabled/default中:17
我看到这个错误很常见,但即使查看其他帖子,我也无法解决问题。我的nginx.conf
文件中有这一行:
include /etc/nginx/sites-enabled/*;
我是否需要删除sites_enables/default
文件中的http行?
当您包含时,它与粘贴匹配文件中的内容一样好。因此,如果我的主要nginx.conf
是
http {
line 1
line 2;
include sites-enabled/*.conf;
}
和 sites-enabled/default.conf
在
http {
server {
line 3;
}
}
有效配置变为
http {
line 1;
line 2;
http {
server {
line 3;
}
}
}
现在http
在任何其他指令内都不允许使用指令,您可以在根级别使用它。因此,"http" directive is not allowed here
的错误。您应该运行nginx -T
以查看其使用的完整组合配置。
修复程序很简单,从default
文件中删除http
封闭块,因为您已经在http
块内部