2014-09-24 93 views
0

首先,对不起我的英文(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

回答

0

对不起T^T
我解决了这个问题。

我正在使用云服务器。
突然间,想到在云服务器网站堡转发罢工我。
允许在网站3000,3001端口..它运作良好...!

每个人都点击不清楚的问题..对于阅读这个问题抱歉。 X(

祝您有美好的一天!