Reputation: 387
First, sorry for my English (T^T)
I want to run three apps.
(actually, one app. only Difference is environment (development, staging, production))
so I modify some conf codes.
but only working on 80 port!
If I change port of server on working (listening 80) to 81, it not works on port 81 T^T.
I dont know why it is only working on 80 port
Here is my my_app_nginx.conf, deploy.rb, unicorn.rb, unicorn_init.sh, 'netstat -lnp'
/etc/nginx/sites-enabled/my_app_nginx (it is included nginx.conf)
Three upstrem.
and three server on listening port 80(production), 3000(development), 3001(staging)
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
upstream unicorn_development {
server unix:/tmp/unicorn.chimiseng_development.sock fail_timeout=0;
}
upstream unicorn_staging {
server unix:/tmp/unicorn.chimiseng_staging.sock fail_timeout=0;
}
upstream unicorn_production {
server unix:/tmp/unicorn.chimiseng_production.sock fail_timeout=0;
}
server {
listen 80;
root /bps_data/apps/chimiseng_production/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn_production;
location @unicorn_production {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn_production;
}
error_page 500 502 503 504 /500.html;
error_log /bps_data/apps/chimiseng_production/shared/log/nginx_error.log warn;
access_log /bps_data/apps/chimiseng_production/shared/log/nginx_access.log compression;
client_max_body_size 4G;
keepalive_timeout 10;
}
server {
listen 3000;
root /bps_data/apps/chimiseng_development/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn_development;
location @unicorn_development {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn_development;
}
error_page 500 502 503 504 /500.html;
error_log /bps_data/apps/chimiseng_development/shared/log/nginx_error.log warn;
access_log /bps_data/apps/chimiseng_development/shared/log/nginx_access.log compression;
client_max_body_size 4G;
keepalive_timeout 10;
}
server {
listen 3001;
root /bps_data/apps/chimiseng_staging/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn_staging;
location @unicorn_staging {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn_staging;
}
error_page 500 502 503 504 /500.html;
error_log /bps_data/apps/chimiseng_staging/shared/log/nginx_error.log warn;
access_log /bps_data/apps/chimiseng_staging/shared/log/nginx_access.log compression;
client_max_body_size 4G;
keepalive_timeout 10;
}
For reference.. http://my_domain.com:80 is logged at nginx_access_log
but http://my_domain.com:3000 or :3001 is never logged at nginx_access_log. just leave 0 bytes.
unicorn.rb
environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
root = "/bps_data/apps/chimiseng_#{environment}/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.chimiseng_#{environment}.sock"
worker_processes 2
timeout 30
deploy.rb
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command} #{rails_app}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/chimiseng"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
end
...
...
unicorn_init.sh
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/bps_data/apps/chimiseng_$2/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E $2"
... start|stop|force-stop|restart... codes...
netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
...
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:3001 0.0.0.0:* LISTEN -
...
Active UNIX domain sockets (only servers)
...
unix 2 [ ACC ] STREAM LISTENING 9525914 8564/unicorn.rb -E /tmp/unicorn.chimiseng_development.sock
unix 2 [ ACC ] STREAM LISTENING 9509620 13448/unicorn.rb -E /tmp/unicorn.chimiseng_staging.sock
unix 2 [ ACC ] STREAM LISTENING 9519355 3020/unicorn.rb -E /tmp/unicorn.chimiseng_production.sock
...
I tried to "nginx restart" and sh -c "/etc/init.d/unicorn_chimiseng_ENVIRONMENT restart ENVIRONMENT" not working.
But you can see netstat -lnp.. listen ports well and the socks is active.
And there is no default deferred options at nginx 'listen'
Why cannot use ports except for 80 ??
please help me T^T
Upvotes: 0
Views: 1583
Reputation: 387
Sorry T^T
I resolved this problem.
I'm using a cloud server.
All of a sudden, thinking about Fort forwarding in cloud server web site strike me.
Allow for 3000, 3001 port in the web site.. it works well...!
Every body click down unclear question.. sorry for reading this question. X(
Have a nice day!
Upvotes: 0