使用nginx

时间:2016-10-12 13:09:57

标签: nginx amazon-ec2

我不得不为坏网关打开另一张票。我尝试在Ubuntu上使用手动安装步骤(在AWS EC2服务器上):https://github.com/cantino/huginn/blob/master/doc/manual/installation.md

我在nginx日志中收到以下内容的502坏网关: * 4连接上游时连接()到unix:/home/huginn/huginn/tmp/sockets/unicorn.socket失败(2:没有这样的文件或目录)

我更改了Procfile和nginx配置以侦听尝试在另一个位置创建套接字文件,结果如下: 连接到上游时connect()到unix:/var/sockets/unicorn.huginn.socket失败(2:没有这样的文件或目录)

然后,我更改了Procfile和nginx配置以收听127.0.0.1:3000并获取: *连接上游时,1连接()失败(111:拒绝连接)

我相信我有独角兽跑,但由于某种原因,nginx没有在同一个插座上听:

ubuntu@ip-172-31-62-157:/home/huginn/huginn/config$ ps aux | grep unicorn
huginn   21407 46.0  2.1  93944 21880 ?        Rl   11:54   0:02 /home/huginn/huginn/vendor/bundle/ruby/2.3.0/bin/unicorn -c config/unicorn.rb
ubuntu   21417  0.0  0.0  10460   940 pts/0    S+   11:54   0:00 grep --color=auto unicorn

我还需要解决哪些问题?我对此非常敏感 - 任何指针都表示赞赏!

我的Unicorn.rb如下:

wd = File.expand_path(File.join(File.dirname(__FILE__), '..'))

app_path = wd

worker_processes 2
preload_app true
timeout 180
# listen "#{wd}/tmp/sockets/unicorn.socket"
listen "127.0.0.1:3000"

working_directory app_path

rails_env = ENV['RAILS_ENV'] || 'production'

# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"

# Set master PID location
pid "#{wd}/tmp/pids/unicorn.pid"

before_fork do |server, worker|
  ActiveRecord::Base.connection.disconnect!
  old_pid = "#{server.config[:pid]}.oldbin"
  if File.exist?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end
end

after_fork do |server, worker|
  ActiveRecord::Base.establish_connection
end

nginx config:

## Huginn
##
## Lines starting with two hashes (##) are comments with information.
## Lines starting with one hash (#) are configuration parameters that can be uncommented.
##
###################################
##         configuration         ##
###################################
##
## See installation.md#using-https for additional HTTPS configuration details.

# upstream huginn {
#  server unix:/home/huginn/huginn/tmp/sockets/unicorn.socket fail_timeout=0;
# }

upstream huginn {
  server 127.0.0.1:3000 fail_timeout=0;
}
## Normal HTTP host
server {
  listen 0.0.0.0:80 default_server;
  listen [::]:80 ipv6only=on default_server;
  server_name ec2-54-209-37-232.compute-1.amazonaws.com; ## Replace this with something like huginn.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  root /home/huginn/huginn/public;

  ## Increase this if you want to upload large attachments
  client_max_body_size 20m;

  ## Individual nginx logs for this Huginn vhost
  access_log  /var/log/nginx/huginn_access.log;
  error_log   /var/log/nginx/huginn_error.log;

  location / {
    ## Serve static files from defined root folder.
    ## @huginn is a named location for the upstream fallback, see below.
    try_files $uri $uri/index.html $uri.html @huginn;
  }

  ## If a file, which is not found in the root folder is requested,
  ## then the proxy passes the request to the upsteam (huginn unicorn).
  location @huginn {
    ## If you use HTTPS make sure you disable gzip compression
    ## to be safe against BREACH attack.
    # gzip off;

    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;

    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;

    proxy_pass http://huginn;
  }

  ## Enable gzip compression as per rails guide:
  ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  ## WARNING: If you are using relative urls remove the block below
  ## See config/application.rb under "Relative url support" for the list of
  ## other files that need to be changed for relative url support
  location ~ ^/(assets)/ {
    root /home/huginn/huginn/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  error_page 502 /502.html;

Procfile:

###############################
#         DEVELOPMENT         #
###############################

# Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job)
# web: bundle exec rails server -p ${PORT-3000} -b ${IP-0.0.0.0}
# jobs: bundle exec rails runner bin/threaded.rb

# Old version with separate processes (use this if you have issues with the threaded version)
# web: bundle exec rails server
# schedule: bundle exec rails runner bin/schedule.rb
# twitter: bundle exec rails runner bin/twitter_stream.rb
# dj: bundle exec script/delayed_job run

###############################
#         PRODUCTION          #
###############################

# You need to copy or link config/unicorn.rb.example to config/unicorn.rb for both production versions.
# Have a look at the deployment guides, if you want to set up huginn on your server:
# https://github.com/cantino/huginn/doc

# Using the threaded worker (consumes less RAM but can run slower)
web: bundle exec unicorn -c config/unicorn.rb
jobs: bundle exec rails runner bin/threaded.rb

# Old version with separate processes (use this if you have issues with the threaded version)
# web: bundle exec unicorn -c config/unicorn.rb
# schedule: bundle exec rails runner bin/schedule.rb
# twitter: bundle exec rails runner bin/twitter_stream.rb
# dj: bundle exec script/delayed_job run

###############################
# Multiple DelayedJob workers #
###############################
# Per default Huginn can just run one agent at a time. Using a lot of agents or calling slow
# external services frequently might require more DelayedJob workers (an indicator for this is
# a backlog in your 'Job Management' page).
# Every uncommented line starts an additional DelayedJob worker. This works for development, production
# and for the threaded and separate worker processes. Keep in mind one worker needs about 300MB of RAM.
#
#dj2: bundle exec script/delayed_job -i 2 run
#dj3: bundle exec script/delayed_job -i 3 run
#dj4: bundle exec script/delayed_job -i 4 run
#dj5: bundle exec script/delayed_job -i 5 run
#dj6: bundle exec script/delayed_job -i 6 run
#dj7: bundle exec script/delayed_job -i 7 run
#dj8: bundle exec script/delayed_job -i 8 run
#dj9: bundle exec script/delayed_job -i 9 run
#dj10: bundle exec script/delayed_job -i 10 run

0 个答案:

没有答案