Answer the question
In order to leave comments, you need to log in
Problem with nginx + unicorn. Why is only the main page working?
Hello. There is an application on Rails 3.2.2 (running on a production server). You need to make changes to it + later install it on the client servers. I, in accordance with the parameters of the main server, set up the environment of the new server, copied the application and its database (mysql). The application starts, but only the main page works, when you go somewhere - Routing error (although everything is in the rake routes listing). Also, there is no access to assets on the server. The server configs are the same (except for the server name in nginx.conf).
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
include sites-enabled/*;
}
upstream e-script_upstream {
server unix:/tmp/unicorn.site.sock fail_timeout=0;
}
server {
server_name www.site.com.ua site.com.ua;
sendfile on;
server_tokens off;
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_proxied any;
gzip_min_length 1100;
gzip_buffers 12 4k;
gzip_types text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# client_header_timeout 60;
# client_body_timeout 260;
# send_timeout 260;
# keepalive_timeout 60;
# proxy_read_timeout 1800;
client_max_body_size 200M;
keepalive_timeout 5;
root /var/www/site/public;
if ($host != 'www.site.com.ua' ) {
rewrite ^/(.*)$ http://www.site.com.ua/$1 permanent;
}
location ~ ^/uploads/ {
expires max;
add_header Cache-Control public;
access_log off;
add_header Last-Modified "";
add_header ETag "";
break;
}
location ~ ^/assets/ {
# gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
access_log off;
add_header Last-Modified "";
add_header ETag "";
break;
}
try_files $uri/index.html $uri.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://site_upstream;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/site/public;
}
}
APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
require "redis"
worker_processes 2
#user "unprivileged_user", "unprivileged_group"
working_directory APP_ROOT
listen "/tmp/unicorn.site.sock", :backlog => 64
#listen 8081, :tcp_nopush => true
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
pid "#{APP_ROOT}/tmp/pids/unicorn.pid"
stderr_path "#{APP_ROOT}/log/unicorn.stderr.log"
stdout_path "#{APP_ROOT}/log/unicorn.stdout.log"
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
sleep 1
end
after_fork do |server, worker|
# per-process listener ports for debugging/admin/migrations
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
$redis = Redis.connect
end
Answer the question
In order to leave comments, you need to log in
Dig towards user rights. Who runs nginx? Who is the app from? What are the rights to assets?
Most likely, the problem is that you have upstream e-script_upstream
, and then a block is defined in the config location @app {}
, and it’s not at all proxy_pass http://site_upstream;
clear where in it.
Also, try location ^~ /assets/
insteadlocation ~ ^/assets/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question