较新的 nginx (1.0.6) 未在 ubuntu 服务器上运行

较新的 nginx (1.0.6) 未在 ubuntu 服务器上运行

使用 ubuntu repo 中的 apt-get 安装了 nginx 0.8.54。执行命令“passenger-install-nginx-module”安装了 nginx 1.0.6(我相信)。但是重启后,nginx -v 仍然显示版本 0.8.54。如何启动 nginx 1.0.6?

这是在 /opt/nginx/sbin 1.0.6 下启动 nginx 时出现的错误(停止当前 nginx 服务器后):

    dtt@ubuntu:/etc$ sudo /opt/nginx/sbin/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] 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] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx
: [emerg] still could not bind() 

谢谢。

答案1

执行命令passenger-install-nginx-module安装 nginx 1.0.6(我相信)

如果你留意安装过程,就会发现,默认情况下它使用 安装Nginx --prefix=/opt/nginx,因此你必须使用绝对路径:

$ /opt/nginx/sbin/nginx -v
nginx: nginx version: nginx/1.0.6

$ /opt/nginx/sbin/nginx -V 
nginx: nginx version: nginx/1.0.6 
nginx: built by gcc 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) 
nginx: TLS SNI support enabled 
nginx: configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-cc-opt=-Wno-error --add-module=/home/dtt/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9/ext/nginx

你为什么说它仍然显示 0.8.54?

如何启动nginx 1.0.6?

首先停止Nginx 0.8.54:

# /etc/init.d/nginx stop

或者:

# /usr/sbin/nginx -s stop

然后使用以下命令启动 Nginx 1.0.6:

# /opt/nginx/sbin/nginx

不要忘记将初始化脚本编辑为新的二进制文件和配置,如下所示:

start() {
    configtest || return 1
    ebegin "Starting nginx"
    start-stop-daemon --start --pidfile /var/run/nginx.pid \
        --exec /opt/nginx/sbin/nginx -- -c /opt/nginx/conf/nginx.conf
    eend $? "Failed to start nginx"
}

相关内容