-1

I've installed RoR, ruby, passenger and nginx on EC2 Ubuntu instance. Now I'm striving to make it work and be accessible only for the ec2's address which looks this http://ec2-11-222-333-44.ap-southeast-2.compute.amazonaws.com/

So I've done everything needed. However, I can't figure out how to setup nginx. Here my /etc/nginx/nginx.conf:

user www-data;
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;

  ##
  # 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/x-javascript text/xml application/xml application/xml+rss text/javascript;

  ##
  # nginx-naxsi config
  ##
  # Uncomment it if you installed nginx-naxsi
  ##

  #include /etc/nginx/naxsi_core.rules;

  ##
  # nginx-passenger config
  ##
  # Uncomment it if you installed nginx-passenger
  ##

  #passenger_root /usr;
  #passenger_ruby /usr/bin/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;
# }
#}


server {
        listen       80;
        server_name  localhost;
        root   /home/ubuntu/my_app/public;
        passenger_enabled on;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /home/ubuntu/my_app/public;
        }
}

My questions:

  1. Do I have to have an index.html in /my_app/public directory? If so then why? It's a Rails app, not a static app?

  2. Do I have to specify root /home/ubuntu/my_app/public; If so what does it have to do with the /public directory? Again, it's a Rails app, not a static app?

  3. What should I do just to make it work?

Incerteza
  • 117
  • 2
  • 11

1 Answers1

1

Some Answers:

  1. No.
  2. Only specify root at the start of your server { block, check out Nginx Pitfalls
  3. I'm pretty sure it's the commented section in your nginx.conf:

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;
    

You are not pointing them to Passenger + Ruby. (What does nginx run when it gets a request? Nothing, that's what.)

Check out this blog Setup RoR + Passenger on AWS for setting up RoR + Passenger

Below is a copy of a working nginx.conf and a sample virtual directory for your reference.

nginx.conf:

user  deploy;
worker_processes  4;

error_log  logs/error.log;
events {
    worker_connections  1024;
}

http {
    server_names_hash_bucket_size 128;
    passenger_max_pool_size 200;
    rails_app_spawner_idle_time 600;
    passenger_pool_idle_time 300;
    passenger_debug_log_file /opt/nginx/logs/passenger-error.log;
    passenger_log_level 2;
    passenger_root /usr/local/rvm/gems/ruby-1.8.7-p371@rails2.3.15/gems/passenger-3.0.19;
    passenger_ruby /usr/local/rvm/wrappers/ruby-1.8.7-p371@rails2.3.15/ruby;
    client_max_body_size 15M;

    include       mime.types;
    log_format main     '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  20;
    gzip  on;

    server {
        listen       80;
        server_name  localhost;
        error_page 403 /403.html;
        error_page 404 /404.html;
        location / {
            root   html;
            index  index.html index.htm index.php;
        }

#  Parse all .php file in the /var/www directory
    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(.*)$;
        fastcgi_pass   backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }   

#        Disable viewing .htaccess & .htpassword
    location ~ /.ht {
        deny  all;
    }
 }
upstream backend {
        server unix:/var/run/php5-fpm.sock;

}

Virtual Host.conf:

server {
    server_name domain.com.au;
    rewrite ^(.*) http://www.domain.com.au$1 permanent;
  }
  server  {
    listen 80;
    server_name www.domain.com.au;
    root "/home/deploy/apps/domain_com_au/current/public";
    passenger_enabled on;
    rails_env production;

    # Set custom access/error logs for awstats
    access_log  /opt/nginx/logs/domain.com.au-access.log;
    error_log  /opt/nginx/logs/domain.com.au-error.log;

    # Configure /cgi-bin/scripts to go through php-fastcgi
    location ~ ^/cgi-bin/.*.(cgi|pl|py|rb) {
        gzip off;
        fastcgi_pass  backend;
        fastcgi_index cgi-bin.php;
        fastcgi_param SCRIPT_FILENAME    /opt/nginx/cgi-bin.php;
        fastcgi_param SCRIPT_NAME        /cgi-bin/cgi-bin.php;
        fastcgi_param X_SCRIPT_FILENAME  /usr/lib$fastcgi_script_name;
        fastcgi_param X_SCRIPT_NAME      $fastcgi_script_name;
        fastcgi_param QUERY_STRING       $query_string;
        fastcgi_param REQUEST_METHOD     $request_method;
        fastcgi_param CONTENT_TYPE       $content_type;
        fastcgi_param CONTENT_LENGTH     $content_length;
        fastcgi_param GATEWAY_INTERFACE  CGI/1.1;
        fastcgi_param REQUEST_URI        $request_uri;
        fastcgi_param DOCUMENT_URI       $document_uri;
        fastcgi_param DOCUMENT_ROOT      $document_root;
        fastcgi_param SERVER_PROTOCOL    $server_protocol;
        fastcgi_param REMOTE_ADDR        $remote_addr;
        fastcgi_param REMOTE_PORT        $remote_port;
        fastcgi_param SERVER_ADDR        $server_addr;
        fastcgi_param SERVER_PORT        $server_port;
        fastcgi_param SERVER_NAME        $server_name;
        fastcgi_param REMOTE_USER        $remote_user;
    }
  }
techraf
  • 4,243
  • 8
  • 29
  • 44
ticoombs
  • 248
  • 1
  • 4