我知道有重复的问题,但是我的情况似乎无法解决这个问题。
我正在关注一篇关于使用 apache 设置 nginx 作为反向代理的文章。
我收到此错误:
nginx: [emerg] "server" directive is not allowed here in
/etc/nginx/v.hosts/mydomain.com.conf:3
nginx: configuration file /etc/nginx/nginx.conf test failed
我的/etc/nginx/nginx.conf
样子是这样的:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log main;
charset utf-8;
keepalive_timeout 65;
server_tokens off;
tcp_nopush on;
tcp_nodelay off;
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html index.htm;
}
}
include v.hosts/*.conf;
我所/etc/nginx/v.hosts/mydomain.com.conf
看到的是这样的:
server {
listen 80;
server_name mydomain.com;
access_log off;
error_log off;
location / {
proxy_pass http://127.0.0.1:81;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
}
}
如能提供线索和帮助将不胜感激:)
答案1
问题在于:
}
include v.hosts/*.conf;
您已关闭指令http
前的块include
,从而结束配置。这就是所有包含的文件都不起作用的原因。
要修复此问题,块include
内的文件http
:
include v.hosts/*.conf;
}