首先,對不起我的英文(T^T)rails nginx獨角獸多聽端口
我想運行三個應用程序。
(實際上,只有一個應用程序)區別在於環境(開發,分期,製作))
所以我修改了一些conf代碼。
但只能在80端口上工作!
如果我改變工作(80聽)服務器的端口81,它不在端口81 T^T的作品。
我不知道爲什麼它只有80端口
這裏的工作是我的my_app_nginx.conf,deploy.rb,unicorn.rb,unicorn_init.sh,用 'netstat -lnp'
/等/ nginx的//my_app_nginx(它是包含nginx.conf)啓用站點,
三upstrem。 三上偵聽端口80(生產),3000(開發),3001(分期)
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;
}
僅供參考..3210服務器記錄在nginx_access_log
但http://my_domain.com:3000或:在nginx_access_log從未記錄3001。只留下0個字節。
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
...
我試圖 「重啓nginx的」 和sh -c 「/etc/init.d/unicorn_chimiseng_ENVIRONMENT重新啓動環境」 不工作。
但是你可以看到netstat -lnp .. listen端口和襪子是活動的。
並且nginx沒有默認的延遲選項'listen'
爲什麼不能使用除80以外的端口?
請幫我T^T