如果我跑:
$ sudo service nginx status
* nginx is not running
然后我跑:
$ sudo service nginx start
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
...
nginx: [emerg] still could not bind()
所以我杀了它:
sudo fuser -k 80/tcp
所以我尝试再次启动 Nginx:
$ sudo service nginx start
Starting nginx: nginx.
现在应该正在运行,对吧?:
$ sudo service nginx status
* nginx is not running
我试过了:
$ ps aux | grep nginx
root 1316 0.0 0.2 64988 1236 ? Ss 14:37 0:00 nginx: master process /usr/sbin/nginx
nobody 1317 0.0 0.3 65408 1908 ? S 14:37 0:00 nginx: worker process
myusername 1436 0.0 0.1 9388 876 pts/2 S+ 14:40 0:00 grep nginx
当我访问该站点的 ip 时。nginx/1.2.1
我在底部收到一条 404 消息。在我看来,它实际上正在运行。我在 nginx.conf 中阻止了 ip 地址,我测试了这些 ip 目前正在被阻止。所以我对 Nginx 是否正在运行以及如何抓住这个野兽感到困惑。
我的最终目标是让 Gunicorn 也能运行。奇怪的是这一切昨天都在工作。Gunicorn 和 Nginx 的状态均为working
.
404 = 找不到页面。
这意味着 nginx 正在为请求提供服务(同时你没有在端口 80 上运行任何其他东西)。从它的声音来看,服务器已经正常启动。只需在您的 nginx 目录根目录中使用“hello world”创建一个 index.htm 文件,然后您就会看到一些东西。
也许您在同一端口上运行了 apache,而 nginx 无法绑定该地址,因为它已被使用。
要更改 nginx 的端口,请查看 stackoverflow 上的回复 [1] https://stackoverflow.com/questions/10829402/how-to-start-nginx-via-different-portother-than-80
这里有一个关于我的哈巴狗的例子
您是否更改了 pid 文件的位置?通常,当您启动服务时,它会检查它是否已经在运行,如果是则不执行任何操作,否则将启动它。所以你得到的那些绑定错误不应该发生。
vinit 的 nginx pid 文件的默认位置是 /var/run/nginx.pid。