【问题标题】:Application running nginx server not showing up运行 nginx 服务器的应用程序未显示
【发布时间】:2015-09-20 16:43:02
【问题描述】:

我在 Digital Ocean 中有一个 Rails 应用程序,运行 nginx、ubuntu 14.04、postgresql 和 capistrano。

问题是当我访问我的服务器地址 (xxx.xxx.xxx.xxx) 时它没有显示,这是在我使用 cap production deploy 推送到服务器之后发生的,我已经完成了这些命令好吧:

sudo service nginx restart sudo service nginx reload touch tmp/restart.txt

什么也没有,当我用 sudo nginx -t 检查配置文件状态时,它说:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

为什么会这样?有什么线索吗?

这是我的 nginx.conf 文件:

user deploy;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Phusion Passenger config
    ##
    # Uncomment it if you installed passenger or passenger-enterprise
    ##

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /home/deploy/.rbenv/shims/ruby;

    # passenger_root    /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    # passenger_ruby /usr/bin/passenger_free_ruby;

    ##
    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    }


    #mail {
    #       # See sample authentication script at:
    #       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
    #
    #       # auth_http localhost/auth.php;
    #       # pop3_capabilities "TOP" "USER";
    #       # imap_capabilities "IMAP4rev1" "UIDPLUS";
    #
    #       server {
    #               listen     localhost:110;
    #               protocol   pop3;
    #               proxy      on;
    #       }
    #
    #       server {
    #               listen     localhost:143;
    #               protocol   imap;
    #               proxy      on;
    #       }
    #}

提前致谢。

【问题讨论】:

  • 你能粘贴你的 nginx.conf 文件吗?另外,ps aux | grep nginx 的输出是什么
  • @DaniG2k 我添加了我在 nginx.conf 上的代码,我从你给我的命令中得到的输出在这里:pastebin.com/VM2RNNsb
  • 看起来你使用 Phusion 乘客和 nginx (我提到因为你说你跑了touch tmp/restart.txt,当你尝试访问服务器 IP 时,你得到什么错误/消息?另外,作为旁注您可以运行一个名为 BIND 的服务,它将 IP 地址转换为域名,因此您无需输入 IP 地址即可访问服务器。
  • 我还会在您的问题中发布access.logerror.log 的输出。

标签: ruby-on-rails ubuntu nginx capistrano


【解决方案1】:

首先,如果您的应用程序使用的是 PostgreSQL,请确保它使用正确的用户、数据库和表按预期启动和运行。

然后,您可能需要检查passenger_rootpassenger_ruby 指令是否正确。我有以下内容:

passenger_root /home/myuser/.rvm/gems/ruby-2.2.2/gems/passenger-5.0.18;
passenger_ruby /home/myuser/.rvm/gems/ruby-2.2.2/wrappers/ruby;

另外,我不确定在您的 http 块中包含 SSL 配置是否正确。我相信 SSL 指令属于 https 块。您还需要确保user deploy 存在且正确。

我看到你也有这个指令:

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

您需要确保 /etc/nginx/sites-enabled/ 中有一个文件定义了指向您网站的服务器块,例如:

server {
  listen                80;
  server_name           <some IP address here> yourdomain.com;
  root                  /home/youruser/yourwebsite/public;
  passenger_enabled     on;

  location ~ ^/(assets)/ {
    expires max;
    add_header Cache-Control public;
    gzip_static on;
  }
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   html;
  }
}

(此配置假设您有一个 Ruby on Rails 网站。您需要针对您的应用程序进行相应调整。)这里的基本部分是 server_name 指令,它告诉 Nginx 响应该 DNS 条目并执行某些操作。

能否请您也找到您遇到的具体错误消息。您可能需要查看 nginx 日志或应用程序的日志以了解错误是什么。

【讨论】:

  • 我需要在 server_name 上放置一个域吗?如果我目前没有怎么办?知道我有它就像示例 yourdomain.com
  • 如果您没有域名,请删除域名并输入已分配给您的 IP 地址。
猜你喜欢
  • 2020-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-06
  • 2021-07-22
  • 1970-01-01
  • 2017-09-19
  • 1970-01-01
相关资源
最近更新 更多