【问题标题】:Apache2 Ubuntu Default Page Showing Up出现 Apache2 Ubuntu 默认页面
【发布时间】:2017-08-07 22:32:57
【问题描述】:

一直在使用 Rails 5 并通过 Vagrant 设置一切。我已经成功地让我的网站通过 Nginx 和 Webrick 运行。当我尝试使用 Unicorn 时,它会显示 Apache2 默认页面。我删除了sites-available 中的默认值,并在sites-enabled 下创建了一个链接到nginx.conf 的默认值。

这是我的nginx.conf 文件:

upstream unicorn {
  server unix:/tmp/unicorn.mysiteNginx.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  # server_name projectname.com;
  root /vagrant/public;
  try_files $uri/home.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
  }

unicorn.rb 文件:

working_directory "/vagrant"
pid "/vagrant/tmp/pids/unicorn.pid"
stderr_path "/vagrant/log/unicorn.log"
stdout_path "/vagrant/log/unicorn.log"

listen "/tmp/unicorn.mysiteNginx.sock"
worker_processes 2
timeout 30

unicorn_init.sh文件:

#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals

# Feel free to change any of the following variables for your app:
# Remember -E production flag for production & sudo -c "$CMD" - user so it's not run as root!
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/vagrant
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="/home/vagrant/.rvm/bin/ruby-2.3.1_unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
action="$1"
set -u

old_pid="$PID.oldbin"

cd $APP_ROOT || exit 1

sig () {
        test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
        test -s $old_pid && kill -$1 `cat $old_pid`
}

case $action in
start)
        sig 0 && echo >&2 "Already running" && exit 0
        su -c "$CMD" - vagrant
        ;;
stop)
        sig QUIT && exit 0
        echo >&2 "Not running"
        ;;
force-stop)
        sig TERM && exit 0
        echo >&2 "Not running"
        ;;
restart|reload)
        sig HUP && echo reloaded OK && exit 0
        echo >&2 "Couldn't reload, starting '$CMD' instead"
        su -c "$CMD" - vagrant
        ;;
upgrade)
        if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
        then
                n=$TIMEOUT
                while test -s $old_pid && test $n -ge 0
                do
                        printf '.' && sleep 1 && n=$(( $n - 1 ))
                done
                echo

                if test $n -lt 0 && test -s $old_pid
                then
                        echo >&2 "$old_pid still exists after $TIMEOUT seconds"
                        exit 1
                fi
                exit 0
        fi
        echo >&2 "Couldn't upgrade, starting '$CMD' instead"
        su -c "$CMD" - vagrant
        ;;
reopen-logs)
        sig USR1
        ;;
*)
        echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
        exit 1
        ;;
esac

在提交此问题之前,我对堆栈溢出进行了一些研究,并对类似问题进行了一些故障排除,但到目前为止没有成功。任何帮助将不胜感激!

---更新 1---

当我执行sudo service unicorn restart 时,这就是error.log 中显示的内容:

017/08/07 22:41:17 [notice] 2387#2387: signal process started
2017/08/07 22:41:18 [emerg] 2391#2391: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/07 22:41:18 [emerg] 2391#2391: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/07 22:41:18 [emerg] 2391#2391: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/07 22:41:18 [emerg] 2391#2391: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/07 22:41:18 [emerg] 2391#2391: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/07 22:41:18 [emerg] 2391#2391: still could not bind()

---更新 2---

sudo lsof -i:80之后登录

COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1854     root    6u  IPv4  11471      0t0  TCP *:http (LISTEN)
nginx   1855 www-data    6u  IPv4  11471      0t0  TCP *:http (LISTEN)

【问题讨论】:

  • 你需要查看nginx日志。有时是因为你需要创建 tmp 和 pids 目录。
  • 你需要一个Apache2进程在一边运行吗?如果不这样做,请尝试阻止它。
  • 你需要定义server_name。
  • 在上面的更新中查看 error.log 中显示的内容。至于创建tmppids 目录,它们是在我的vagrant 文件夹中创建的,我的项目依赖于unicorn.pid
  • @AndréGuimarãesSakata 我已经停止了它,但它显示一个空响应

标签: ruby-on-rails nginx vagrant unicorn


【解决方案1】:

首先你应该运行 ***

sudo systemctl stop apache2


之后

sudo systemctl 重启 nginx

sudo systemctl reload nginx

【讨论】:

    【解决方案2】:

    EADDRINUSE (98) 错误非常明显。您不能将多个网络服务器绑定 (2) 到端口 80。其中一个必须离开,以便为您喜欢的一个腾出空间。

    使用sudo lsof -i:80 来识别已经绑定到该TCP 端口的进程。 Root 应该发出kill 或类似service apache stop 的命令来临时允许另一台服务器获取端口。从长远来看,systemctl disable apache 之类的东西将确保端口 80 在重新启动后仍然可用。或者在其配置文件中切换到非默认端口。

    【讨论】:

    • 是的,通过阅读日志,我也预计这将是问题所在。等我回来试试你的方法。我所知道的是,我已经通过执行sudo service apache2 stop 停止了 apache,但什么都不会发生。如果我重新加载 vagrant 并重新启动 nginx 和 unicorn,apache 就会启动并运行。它要么完全杀死它(就像你推荐的那样),要么完全从服务器中删除 apache。
    • 在使用sudo lsof -i:80 后对我的问题添加了第二次更新。根目录旁边没有看到任何kill。我也使用了systemctl disable apache,但它说找不到该命令。另一件事是我最终决定卸载 apache 2 只是为了看看它是否可以工作。
    猜你喜欢
    • 2013-10-28
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    相关资源
    最近更新 更多