为什么nginx无法启动?

为什么nginx无法启动?,nginx,Nginx,但启动nginx失败,我的日志显示: [emerg] 55#55: "server" directive is not allowed here in /etc/nginx/nginx.conf:1 我做错了什么?不确定这是否重要,但这是在docker容器中。/etc/nginx/nginx.conf不是存储服务器设置的地方。此文件应包含有关将在其下运行的用户和其他全局设置的信息。通常,它将包含以下内容: user www-data; worker_processes 4; pid /run/

但启动nginx失败,我的日志显示:

[emerg] 55#55: "server" directive is not allowed here in /etc/nginx/nginx.conf:1

我做错了什么?不确定这是否重要,但这是在docker容器中。

/etc/nginx/nginx.conf
不是存储服务器设置的地方。此文件应包含有关将在其下运行的用户和其他全局设置的信息。通常,它将包含以下内容:

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
块中


因此,请将您发布的示例配置存储在
/etc/nginx/sites enabled/some random name.conf
中,然后将
nginx.conf
文件恢复到我在上面发布的配置中,您应该准备好了。

/etc/nginx/nginx.conf
不是存储服务器设置的地方。此文件应包含有关将在其下运行的用户和其他全局设置的信息。通常,它将包含以下内容:

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
块中


因此,请将您发布的示例配置存储在
/etc/nginx/sites enabled/some random name.conf
中,然后将
nginx.conf
文件还原到我上面发布的配置中,您就可以开始了。

首先尝试用

sudo nginx -t
如果此操作通过,但nginx重新启动失败,请尝试检查 您的nginx日志可以缩小bug的范围

/var/log/nginx/error.log

首先尝试使用调试

sudo nginx -t
如果此操作通过,但nginx重新启动失败,请尝试检查 您的nginx日志可以缩小bug的范围

/var/log/nginx/error.log

不看你的配置就说不出来。。。可能与错误位置的服务器指令有关。如果不查看您的配置,很难说。。。可能与错误位置的服务器指令有关。