Rails + Passenger + Nginx 404 Not found - ruby-on-rails

I'm working with Rails + Passenger + Nginx
My project (Redmine) is in /var/www/tracker-continuity/current (and project in public).
I don't know why when I try to access to my serveur it's always a 404 Error page. We can see it in log
[ N 2018-06-05 14:23:20.6491 20067/T1 age/Cor/CoreMain.cpp:1236 ]: Starting Passenger core...
[ N 2018-06-05 14:23:20.6494 20067/T1 age/Cor/CoreMain.cpp:251 ]: Passenger core running in multi-application mode.
[ N 2018-06-05 14:23:20.6631 20067/T1 age/Cor/CoreMain.cpp:971 ]: Passenger core online, PID 20067
2018/06/05 14:23:31 [error] 20084#20084: *1 "/var/www/trackeur-continuity/current/public/index.html" is not found (2: No such file or directory), client: someIp, server: hideUrl, request: "GET / HTTP/1.1", host: "hideIp"
Here, part of my nginx.conf and my vhost conf. Extracted from a Nginx dump configuration. (Only Passenger parts)
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
user www-data;
worker_processes 4;
include /etc/nginx/modules-enabled/*.conf;
http {
...
}
# configuration file /etc/nginx/conf.d/mod-http-passenger.conf:
### Begin automatically installed Phusion Passenger config snippet ###
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;
### End automatically installed Phusion Passenger config snippet ###
}
server {
listen 80;
server_name default_server ;
charset utf-8;
root /var/www/trackeur-continuity/current/public;
access_log /var/log/nginx/access.log timed_combined buffer=16k;
error_log /var/log/nginx/error.log;
passenger_enabled on;
rails_env development;
client_max_body_size 110m;
}

Got it !
tracker-continuity not trackeur-continuity

Related

Rails + Nginx + Unicorn - unicorn.sock file is not created when deploying

I'm getting a "We're sorry, but something went wrong" screen upon attempting to deploy. It was previously working fine, however when I tried to update it, I ran into this issue. This is my first time deploying anything, and I'm still not exactly sure what I'm doing so I would really appreciate some input as to what I'm doing incorrectly.
I get the following error from unicorn.log
I, [2018-10-01T19:54:53.470419 #4905] INFO -- : unlinking existing
socket=/home/deploy/production/appName/tmp/sockets
/bcrypt_unicorn.todo.sock
I, [2018-10-01T19:54:53.470635 #4905] INFO -- : listening on addr=/home/deploy/production/appName/tmp/sockets/bcrypt_unicorn.todo.sock fd=10
I, [2018-10-01T19:54:53.470737 #4905] INFO -- : worker=0 spawning...
I, [2018-10-01T19:54:53.471045 #4905] INFO -- : worker=1 spawning...
I, [2018-10-01T19:54:53.471397 #4905] INFO -- : master process ready
I, [2018-10-01T19:54:53.476589 #4908] INFO -- : worker=0 spawned pid=4908
I, [2018-10-01T19:54:53.476714 #4908] INFO -- : Refreshing Gem list
I, [2018-10-01T19:54:53.477787 #4910] INFO -- : worker=1 spawned pid=4910
I, [2018-10-01T19:54:53.477910 #4910] INFO -- : Refreshing Gem list
I, [2018-10-01T19:54:59.740522 #4908] INFO -- : worker=0 ready
I, [2018-10-01T19:54:59.744825 #4910] INFO -- : worker=1 ready
and the following error from /var/log/nginx/error.log:
2018/10/01 20:00:41 [crit] 5067#5067: *2 connect() to unix:/home/deploy
/production/appName/tmp/sockets/bcrypto_unicorn.todo.sock failed
(2: No such file or directory) while connecting to upstream, client:
77.75.77.32, server: , request: "GET /genres/gaming HTTP/1.1", upstream:
"http://unix:/home/deploy/production/appName/tmp/sockets
/bcrypto_unicorn.todo.sock:/genres/gaming", host: "appName.com"
I restarted Nginx with
sudo service nginx restart
Reload the updated configuration
sudo nginx -s reload
Then stopped the running Unicorn process
ps aux | grep "unicorn master"
kill -9 PID
Then pulled updated code to deploy
git status
git stash save -u quick-fix
git pull origin master
git stash apply
Then migrated the db
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake assets:precompile
Then finally restarted Unicorn
bundle exec unicorn -E production -c config/unicorn.rb -D
My unicorn.rb file is as follows:
app_path = "/home/deploy/production/appName"
working_directory app_path
pid app_path + "/tmp/pids/unicorn.pid"
stderr_path app_path + "/log/unicorn.log"
stdout_path app_path + "/log/production.log"
listen app_path + '/tmp/sockets/bcrypt_unicorn.todo.sock'
worker_processes 2
timeout 65
appName/config/nginx.conf
upstream unicorn {
server unix:/tmp/sockets/bcrypto_unicorn.todo.sock fail_timeout=0;
}
server{
listen 80 default deferred;
root /home/deploy/production/appName/public;
try_files $uri/index.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 403 404 /404.html;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
and /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
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 applicati$
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-enabled/bcrypto
upstream bcrypto_unicorn {
server unix:/home/deploy/production/appName/tmp/sockets/bcrypto_unicorn.todo.sock fa$
}
server {
listen 80 default deferred;
root /home/deploy/production/appName/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri #bcrypto_unicorn;
location #bcrypto_unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://bcrypto_unicorn;
}
error_page 422 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 60;
}
Can someone please point me in the direction of what I'm doing incorrectly here?
Firstly, check your tmp/sockets folder to see whether its exists or not. If not, create the folder with following command
mkdir /home/deploy/production/appName/tmp/sockets
Then, change your socket to the same path with nginx by modify your unicorn.rb
listen app_path + '/tmp/sockets/bcrypt_unicorn.todo.sock'
Lastly, restart unicorn
bundle exec unicorn -E production -c config/unicorn.rb -D
The problem is that Nginx is looking for the socket in a different place that Unicorn has set it.
Nginx is trying to find the socket at:
/home/deploy/production/appName/tmp/sockets/byc2-master_unicorn.todo.sock while the Unicorn config is setting it to /tmp/appName_unicorn.todo.sock
To solve the problem both paths must be the same. So you need to place the same path in the upstream directive of /etc/nginx/sites-enabled/bcrypto and the one defined by the listen directive in unicorn.rb
Then restart Unicorn and reload Nginx

Why can't I see my app instead of default nginx test page in production?

After following all the steps in deploying a Rails app in digitalocean using Unicorn and nginx as outlined in the following link enter link description here
, entering my IP address in the browser leads me to default nginx landing page which says: "This is the default index.html page that is distributed with nginx on Fedora. It is located in /usr/share/nginx/html.
You should now put your content in a location of your choice and edit the root configuration directive in the nginx configuration file /etc/nginx/nginx.conf.
Here is my etc/nginx/ngingx.conf:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen [::]:80 default_server;
server_name localhost;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
And here is /etc/nginx/conf.d/default.conf :
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
# Application root, as defined previously
root /root/my_app/public;
try_files $uri/index.html $uri #app;
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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
And also the config/unicorn.rb
#application root path
app_root = "/var/www/mav"
# Set the working application directory
# working_directory "/path/to/your/app"
working_directory app_root
# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "#{app_root}/tmp/pids/unicorn.pid"
# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "#{app_root}/log/unicorn.log"
stdout_path "#{app_root}/log/unicorn.log"
# Number of processes
# worker_processes 4
worker_processes 2
# Time-out
timeout 30
When access the unicorn logs:
tail -20 /var/log/nginx/error.log
2017/12/10 05:06:30 [warn] 8810#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:06:30 [warn] 8818#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:08:31 [error] 8826#0: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 190.104.119.69, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "138.197.195.201", referrer: "http://138.197.195.201/"
2017/12/10 05:29:51 [warn] 19171#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:29:51 [warn] 19176#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:43:49 [warn] 12191#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:43:50 [warn] 12203#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:29 [warn] 11819#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:30 [warn] 11825#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:48 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:01:50 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:01:52 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:57 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:58 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:59 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:59 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:11:38 [emerg] 30474#0: unknown directive "And" in /etc/nginx/nginx.conf:91
2017/12/10 06:12:10 [emerg] 31474#0: unknown directive "And" in /etc/nginx/nginx.conf:91
2017/12/10 06:19:31 [emerg] 12641#0: unexpected end of file, expecting "}" in /etc/nginx/nginx.conf:89
2017/12/10 06:43:30 [emerg] 24459#0: unexpected end of file, expecting "}" in /etc/nginx/nginx.conf:89
There are several misconfigurations. Since you don't provide all of them, I will list them here, then you can check yourself
Where is the folder where your code locate?
I assume it in /var/www/mav as you wrote it in your config/unicorn.rb. It will be your starting point.
The root for your nginx.conf should be /var/www/mav/public
You should remove any index.html file in the /var/www/mav/public folder
Your NginX listen to the unix socket of Unicorn, but your unicorn.rb did not configure it.
Here is what I get from your setup document
# Unicorn socket
listen "/tmp/unicorn.[app name].sock"
listen "/tmp/unicorn.myapp.sock"
After start your unicorn, you should check if it started correctly or not ( ex: via log, via ps command ... )
P/S: Your NginX config name should be etc/nginx/nginx.conf ( without the last g)

Rails application works with ip, but not with domain name in Nginx

In CentOS 7.x I've installed a Rails app which I can access through [ip]:8080. It works using ip.
But when I set the domain name as a server_name (instead of localhost) mydomain.com gives me a 502 Bad Gateway problem. Ip still works.
I already restarted nginx. And the application is running with unicorn_rails. My rails log shows nothing.
PD: This app is from this tutorial.
/etc/nginx/conf.d/default.conf
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80;
server_name mydomain.com www.mydomain.com;
# Application root, as defined previously
root /var/www/my_app/public;
try_files $uri/index.html $uri #app;
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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
/var/www/my_app/config/unicorn.rb
# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/var/www/my_app"
# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/var/www/my_app/pids/unicorn.pid"
# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/var/www/my_app/log/unicorn.log"
stdout_path "/var/www/my_app/log/unicorn.log"
# Unicorn socket
#listen "/tmp/unicorn.[app name].sock"
listen "/tmp/unicorn.myapp.sock"
# Number of processes
# worker_processes 4
worker_processes 2
# Time-out
timeout 30
This is what my /var/log/nginx/error.log shows:
2015/02/17 14:06:34 [crit] 14512#0: *375 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 123.45.678.91, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/", host: "mydomain.com"
2015/02/17 14:06:36 [crit] 14512#0: *375 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 123.45.678.91, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/", host: "mydomain.com"
A second question, the application only executes when I run unicorn_rails, how can I make it run permanently?
Check out this previous answer as it might be the solution to your problem: Nginx cannot find unix socket file with Unicorn (no such file or directory)
The tl;dr version is you might need to create your unicorn socket in a different location. It might be that when you went from being "localhost" to a domain name you are telling the upstream app that you aren't coming from the local filesystem anymore; however, that is conjecture and someone else should chime in.
This post notes that you can't put interprocess communication sockets in /tmp: https://serverfault.com/questions/463993/nginx-unix-domain-socket-error/464025#464025
Seems like requires additional information about your environment:
1) namei -lm /tmp/unicorn.myapp.sock - display all permissions of path
2) ps aux | grep nginx - display nginx owner and group
3) ps axu | grep unicorn - display unicorn owner and group
4) Provide value of user statement from /etc/nginx/nginx.conf

Nginx and Phusion Passenger running but passenger-status showing 0 processes running

I have a rails app on a production server with Passenger and Nginx (with the Passenger module) installed. However, when I go to run rvmsudo passenger-status, it show that 0 processes are running.
For reference, here is my nginx.conf:
#user www-data;
user root;
worker_processes 4;
pid /var/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_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
##
# 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_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
#passenger_ruby /usr/bin/ruby;
passenger_ruby /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
The /etc/nginx/sites-enabled/ directory contains the relevant Server information.
Here is the output of ps aux | grep nginx:
root 11417 0.0 0.0 42412 1076 ? Ss 13:13 0:00 nginx: master process /opt/nginx/sbin/nginx
nobody 11418 0.0 0.0 42852 1844 ? S 13:13 0:00 nginx: worker process
When I go to the site via my web browser, I get a "Welcome to nginx!" landing page.
I'm a total newbie at this stuff so there might be something dumb simple going on but I just need to get this started up. Any help would be greatly appreciated.
Edit:
Output of rvmsudo passenger-status:
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no `secure_path` in `/etc/sudoers`. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.
Version : 4.0.42
Date : 2014-12-22 14:04:17 -0500
Instance: 11417
----------- General information -----------
Max pool size : 6
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
Output of rvmsudo passenger-memory-stats:
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no `secure_path` in `/etc/sudoers`. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.
Version: 4.0.42
Date : 2014-12-22 14:07:57 -0500
------------- Apache processes -------------
*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename, or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.
---------- Nginx processes ----------
PID PPID VMSize Private Name
-------------------------------------
11417 1 41.4 MB 0.1 MB nginx: master process /opt/nginx/sbin/nginx
11418 11417 41.8 MB 0.6 MB nginx: worker process
### Processes: 2
### Total private dirty RSS: 0.71 MB
----- Passenger processes -----
PID VMSize Private Name
-------------------------------
11399 218.3 MB 0.3 MB PassengerWatchdog
11402 491.5 MB 0.4 MB PassengerHelperAgent
11408 232.9 MB 1.1 MB PassengerLoggingAgent
### Processes: 3
### Total private dirty RSS: 1.74 MB
Phusion Passenger author here. I'm 99% sure this is just an Nginx configuration error.
First of all, Phusion Passenger starts your app at the first request, so it's normal that you see '0 processes' -- unless explicitly configured otherwise with passenger_pre_start.
The clue is the fact that you see "Welcome to nginx" when you try to visit your site. In 99% of the cases, this means that you configured your virtual host wrong. Since you redacted your config file, I cannot tell you what exactly is wrong, but it indicates that Nginx is not associating your request with the virtual host block that you intended it to associate with. If you post your unredacted config file and the URL you're accessing with, I can tell you more. But otherwise, I can only tell you to study how Nginx's server name matching works.
#tagCincy: There is one file under /etc/nginx/sites-enabled/ and it looks like this:
server {
listen 443;
server_name REDACTED;
ssl on;
ssl_certificate REDACTED;
ssl_certificate_key REDACTED;
#auth_basic "REDACTED";
#auth_basic_user_file REDACTED;
client_max_body_size 250m;
client_body_buffer_size 128k;
access_log REDACTED;
error_log REDACTED;
root REDACTED;
passenger_enabled on;
rack_env production;
location ~ ^/assets/ {
add_header Cache-Control public;
add_header ETag "";
expires 1y;
break;
}
# disable site via capistrano (cap deploy:web:disable)
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
}
server {
listen 80;
server_name REDACTED;
client_max_body_size 250m;
client_body_buffer_size 128k;
access_log REDACTED;
error_log REDACTED;
rewrite ^ https://www.REDACTED.com$request_uri? break;
}

Nginx Rails app can't deploy

I have an issue with my rails application running with passenger and nginx hosted in Ubuntu 12.04.
In the nginx.conf file below, my "example.com" (Regular HTML) and "redmine.example.com" (Rails app) are working perfectly, but my "crete.example.com" (Another Rails app) is showing "502 bad gateway". I have them both hosted in /var/data with the same permissions and ownerships, also tried different ports, I can't think of something else to try.
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server{
listen 80;
server_name example.com;
root /opt/nginx/html;
}
server{
server_name redmine.example.com;
root /var/data/redmine/public;
passenger_enabled on;
location ~ ^/<SUBURI>(/.*|$){
alias /var/data/redmine/public$1;
passenger_base_uri /redmine;
passenger_app_root /var/data/redmine;
passenger_document_root /var/data/redmine/public;
passenger_enabled on;}
}
server{
server_name crete.example.com;
root /var/data/crete/public;
passenger_enabled on;
location ~ ^/<SUBURI>(/.*|$){
alias /var/data/crete/public$1;
passenger_base_uri /crete;
passenger_app_root /var/data/crete;
passenger_document_root /var/data/crete/public;
passenger_enabled on;}
}
}
This are my Ruby and Rails versions:
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
Rails 4.1.0
My nginx error.log
2014/05/02 12:29:50 [error] 3343#0: *4 upstream prematurely closed connection while reading response header from upstream, client: xxx.xx.xx.xx, server: crete.example.com, request: "GET / HTTP/1.1", upstream: "passenger:/tmp/passenger.1.0.3
323/generation-0/request:", host: "crete.example.com"
Any other conf file you might need to solve this don't hesitate to ask.
Check out your sites-available and sites-enabled and see if your other rails app is included and configured properly. Also, check if these files are included in your nginx.conf

Resources