部署后,我看到标准的nginx"它可以工作!"

时间:2014-10-01 21:53:05

标签: ruby-on-rails nginx capistrano capistrano3

我已经将带有Capistrano的rails应用程序部署到VPS,当我尝试使用“APP_NAME.com”访问它时,我看到标准Nginx的“它有效!”页。

我尝试从index.html文件夹中删除/var/www文件,现在我看到其中的文件夹:appslogtmp

nginx.conf我有:

user nginx web;

pid /var/run/nginx.pid;
error_log /var/www/log/nginx.error.log;

events {
  worker_connections 1024;
  accept_mutex off;
  use epoll;
}

http {
  include mime.types;
  types_hash_max_size 2048;
  server_names_hash_bucket_size 64;
  default_type application/octet-stream;
  access_log /var/www/log/nginx.access.log combined;
  sendfile on;
  tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
  tcp_nodelay off; # on may be better for some Comet/long-poll stuff

  gzip on;
  gzip_http_version 1.0;
  gzip_proxied any;
  gzip_min_length 0;
  gzip_vary on;
  gzip_disable "MSIE [1-6]\.";
  gzip_proxied expired no-cache no-store private auth;
  gzip_comp_level 9;
  gzip_types text/plain text/xml text/css
             text/comma-separated-values
             text/javascript application/x-javascript
             application/atom+xml;

  upstream app_server {
    server unix:/var/www/apps/APP_NAME/socket/.unicorn.sock fail_timeout=0;
  }

  server {

    pagespeed on;
    pagespeed FileCachePath /var/ngx_pagespeed_cache;

    location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
      add_header "" "";
    }

    location ~ "^/ngx_pagespeed_static/" { }
    location ~ "^/ngx_pagespeed_beacon$" { }

    location /ngx_pagespeed_statistics {
      allow 127.0.0.1; allow 5.228.169.73; deny all;
    }

    location /ngx_pagespeed_global_statistics {
      allow 127.0.0.1; allow 5.228.169.73; deny all;
    }

    pagespeed MessageBufferSize 100000;

    location /ngx_pagespeed_message {
      allow 127.0.0.1; allow 5.228.169.73; deny all;
    }

    location /pagespeed_console {
      allow 127.0.0.1; allow 5.228.169.73; deny all;
    }

    charset utf-8;
    listen 80 default deferred; # for Linux
    client_max_body_size 4G;
    server_name _;
    keepalive_timeout 5;
    root /var/www/apps/APP_NAME/current/public;
    try_files $uri/index.html $uri.html $uri @app;

    location ~ ^/(assets)/  {
      root /var/www/apps/APP_NAME/current/public;
      expires max;
      add_header Cache-Control public;
    }

    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app_server;
    }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /var/www/apps/APP_NAME/current/public;
    }
  }
}

我错过了nginx.conf或其他文件中的内容吗?

另外,当我停止nginx服务器时,它没有意义,我看到同一页面。

我不擅长将应用程序部署到服务器,这是我第一次没有Heroku,所以我不知道,你需要知道什么,以帮助解决我的问题。因此,如果您需要任何其他信息,请询问,我会将其添加到问题中。

谢谢!

2 个答案:

答案 0 :(得分:3)

所以,我找到了来自this answer的解决方案。问题出在Apache Web服务器上,它在后台运行并阻止Nginx在80端口上运行。

我已停止Apache服务器并重新启动Nginx,现在一切正常:

sudo apachectl stop
sudo restart nginx

答案 1 :(得分:0)

你必须使用乘客并在nginx配置中设置如下:

    http {
        passenger_root /home/deployer/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.18;
        passenger_ruby /home/deployer/.rvm/wrappers/ruby-1.9.3-p327/ruby;
...

或使用Rack的HTTP服务器,例如Unicorn,并在nginx config中设置:

upstream app_server {
  server unix:/path/to/.unicorn.sock fail_timeout=0;
  ...

server {
  proxy_pass http://app_server;
  ...