Nginx没有运行,没有错误消息

时间:2013-07-25 13:38:28

标签: nginx

我正在尝试启动我的nginx服务器。 当我输入“$> /etc/init.d/nginx start”时,我看到一条消息显示为“Starting nginx:”,然后没有任何反应。没有错误消息,当我检查nginx的状态时,我发现它没有运行。

这是我的/etc/nginx/nginx.conf文件:

worker_processes  4;
daemon off;

error_log  /home/vincent/tmp/nginx.log;

pid        /home/vincent/tmp/nginx.pid;


events {
    worker_connections  1024;
}


http {
default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /home/vincent/tmp/access.log  main;

sendfile        on;

keepalive_timeout  65;

include /etc/nginx/site-enabled/*;

}

这是我的/ etc / nginx / sites-available / default文件:

server {
  listen       80;
  server_name technical-test.neo9.lan; 

  access_log  /var/log/nginx/technical-test.neo9.lan.log main;

  set $home /home/vincent;

  location / {
    alias $home/neo9/web/app/;
    index  index.html;
  }

  location /api/ {
    rewrite  ^/api/(.*)$  /$1 break;
    proxy_pass http://localhost:1234;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
}

8 个答案:

答案 0 :(得分:184)

首先,始终sudo nginx -t验证您的配置文件是否正常。

我遇到了同样的问题。我遇到这个问题的原因是双重的。首先,我不小心将日志文件复制到我的启用站点的文件夹中。我删除了日志文件,并确保启用网站的所有文件都是正确的nginx站点配置。我还注意到我的两个虚拟主机正在侦听同一个域。所以我确保每个虚拟主机都有唯一的域名。

sudo service nginx restart

然后它奏效了。

答案 1 :(得分:9)

您应该检查/var/log/nginx/error.log中的错误。

在我的情况下,我没有为ipv6添加端口。你也应该这样做(如果你在80以外的端口上运行nginx): listen [::]:8000 default_server ipv6only=on;

答案 2 :(得分:3)

检查nginx.conf文件中的守护程序选项。它必须是ON。或者你可以简单地从配置文件中删除这一行。此处完整描述了此选项http://nginx.org/en/docs/ngx_core_module.html#daemon

答案 3 :(得分:3)

在您的/etc/nginx/nginx.conf文件中:

include /etc/nginx/site-enabled/*;

您使用的路径可能是:

/etc/nginx/sites-enabled/default

请注意网站中缺少 s

答案 4 :(得分:3)

有一种情况你默认检查nginx是否在系统中保留80号码端口,检查你是否有像apache这样的服务器,或者系统上存在阻塞80号码端口的任何问题。

1.您可以通过这种方式更改nginx上的端口号,

  

sudo vim / etc / nginx / sites-available / default

将80更改为81或任何其他内容,

  1. 检查一切正常,
  2.   

    sudo nginx -t

    1. 重新启动服务器
    2.   

      sudo service nginx start

      1. 检查nginx的状态:
      2.   

        sudo service nginx status

        希望能够发挥作用

答案 5 :(得分:0)

我的实例遇到了完全相同的问题。我的问题是我忘了允许端口80访问服务器。也许这也是你的问题?

检查您的WHM并确保该网站的IP地址已打开,

答案 6 :(得分:0)

对于它的价值:在编辑nginx.conf文件后,我遇到了同样的问题。我尝试并尝试通过命令sudo nginx restart和其他各种命令重新启动它。他们都没有产生任何输出。命令sudo nginx -t检查配置文件给出了输出sudo: nginx: command not found,这令人费解。我开始认为路径有问题。

最后,我以root身份登录sudo su)并命令sudo nginx restart。现在,该命令显示有关配置文件的错误消息。修好后,它成功重启。

答案 7 :(得分:0)

1。运行上述命令检查配置文件:sudo nginx -t

2. 检查端口冲突。例如,如果 apache2 ps waux | grep apache2)或任何其他服务使用为nginx配置的相同端口(例如端口80),则服务将无法启动并将无提示失败(错误...我朋友的表弟有这个问题...)

相关问题