为什么Nginx无法启动? [英] why does nginx fail to start?

查看:119
本文介绍了为什么Nginx无法启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但是启动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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆