我知道这里有一些愚蠢的,但我似乎无法解决这个在我的情况。
我正在关注设置nginx作为与Apache的反向代理的文章。
我得到这个错误:
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; } }
线索和帮助将不胜感激:)
问题在这里:
} include v.hosts/*.conf;
在include
指令之前closures了http
块,从而结束configuration。 这就是为什么没有包含的文件工作。
要解决这个问题,请在http
块中include
这些文件:
include v.hosts/*.conf; }