2017-08-07 39 views
2

一直与导轨5和通过流浪设置了一切。我已经成功地通过Nginx和Webrick获得了我的网站。当我尝试使用Unicorn时,它会显示我的Apache2默认页面。我删除了默认sites-availablesites-enabled链接到nginx.conf下创建一个。Apache2的Ubuntu的默认页面显示出来

这里是我的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 ---

这是显示error.log当我做sudo service unicorn restart

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) 
+0

您需要看nginx的日志。有时候是因为你需要创建tmp和pids目录。 –

+0

你需要一个Apache2进程吗?如果你不这样做,试着阻止它。 –

+0

而你需要定义server_name。 –

回答

0

EADDRINUSE(98)错误非常明显。你不能让多个web服务器绑定(2)到80端口。其中一个必须去,为你喜欢的那个腾出空间。

使用sudo lsof -i:80,以确定已经绑定到TCP端口的过程。 Root应该发出killservice apache stop等命令暂时允许另一台服务器获取端口。长期来看,像systemctl disable apache这样的东西将确保重新启动后端口80仍然是空闲的。或者在其配置文件中切换到非默认端口。

+0

呀,我还预计,将通过读取日志中的问题。当我回来时,我会尝试你的方法。我所知道的是,我已经通过执行'sudo service apache2 stop'来停止apache,并且什么都不会发生。如果我重新加载vagrant并重新启动nginx和独角兽,apache将启动并运行。它要么完全杀死它(就像你推荐的那样),要么完全从服务器上删除apache。 –

+0

在使用'sudo lsof -i:80'后添加了对我的问题的第二个更新。根没有看到任何'kill'。我也使用过'systemctl disable apache',但它说那个命令没有找到。另一件事是,我终于决定卸载apache 2,看看它是否可以工作。 –