为什么Nginx无法启动? [英] why does nginx fail to start?
问题描述
但是启动nginx失败,并且我的日志显示:
Yet starting nginx fails and my log shows:
[emerg] 55#55: "server" directive is not allowed here in /etc/nginx/nginx.conf:1
我做错了什么?不确定是否重要,但这在docker容器中.
What am I doing wrong? Not sure if it matters but this is inside a docker container.
推荐答案
/etc/nginx/nginx.conf
不是存储服务器设置的地方.该文件应包含有关将在其下运行的用户的信息以及其他全局设置.通常,它将包含以下内容:
/etc/nginx/nginx.conf
is not the place to store your server setups. This file should contain information on the user it will run under and other global settings. Typically it will contain stuff like this:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 500M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
您应该放置各个服务器设置的位置在/etc/nginx/sites-enabled/
中.如您所见,该文件夹内的所有文件都包含在nginx.conf
文件的http
块中.
Where you should put your individual server setups, is in /etc/nginx/sites-enabled/
. As you can see, all files inside that folder are being included in the http
block of your nginx.conf
file.
因此,将您发布的示例配置存储在/etc/nginx/sites-enabled/some-random-name.conf
内,然后将nginx.conf
文件恢复到我上面发布的配置,那么您应该就可以了.
So store the sample config you have posted inside /etc/nginx/sites-enabled/some-random-name.conf
, and restore the nginx.conf
file to the config I posted above, for instance, and you should be good to go.
这篇关于为什么Nginx无法启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!