大佬教程收集整理的这篇文章主要介绍了502错误网关错误Nginx connect()到unix:/tmp/unicorn.sock失败,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我关于服务器故障的第一个问题.我在搜索网络时找不到解决方案.
我正在运行一个运行Nginx的OpenBSD服务器,我没有设置,这是在浏览器中抛出502 Bad Gateway错误. Nginx错误日志显示此错误:
014/04/29 09:43:49 [error] 5236#0: *263 connect() to unix:/tmp/unicorn.sock Failed (61: Connection refused) while connecTing to upstream,client: ###.###.###.###,server:,request: "GET / http/1.1",upstream: "http://unix:/tmp/unicorn.sock:/",host: "sub.domain.com"
这是Nginx.conf的内容
user _Nginx;
worker_processes 2;
pid /var/run/Nginx.pid;
error_log /var/log/httpd.err debug;
events {
worker_connections 1024;
}
http {
include /etc/Nginx/mime.types;
default_type application/octet-stream;
log_format access '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent $bytes_sent '
'"$http_referer" "$http_user_agent" "$sent_http_content_type"';
access_log /var/log/httpd.log access;
upload_progress proxied 1m;
sendfile on;
server_name_in_redirect off;
clienT_Body_timeout 120;
client_header_timeout 120;
keepalive_timeout 20;
send_timeout 120;
upstream mongrel {
server unix:/tmp/unicorn.sock;
}
gzip on;
gzip_vary on;
gzip_min_length 0;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/plain text/javascript text/css text/stylesheet application/x-javascript application/javascript;
gzip_disable "MSIE [1-6]\.";
client_max_body_size 128000M;
clienT_Body_buffer_size 512k;
ssl_session_timeout 60m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:rC4:HIGH:!MD5:!aNULL:!EDH;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:1R_383_11845@;
ssl_certificate /etc/ssl/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;
server {
listen 80;
listen [::]:80;
listen 443 default ssl;
listen [::]:443 default ssl;
charset utf-8;
root /var/sfta/current/PUBLIC;
LOCATIOn ~* ^/(message\/create|dropBox\/create|attachment\/create|attachments) {
upload_pass @internal_upload;
upload_resumable on;
upload_pass_args on;
upload_store /var/data/tmp;
upload_state_store /var/data/tmp/resume;
upload_store_access user:rw group:rw all:rw;
chunked_transfer_encoding on;
proxy_redirect off;
proxy_set_header Host $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 $scheR_383_11845@e;
if ($request_method != POST) {
proxy_pass http://mongrel;
break;
}
# Set specified fields in request body
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.sha1" "$upload_file_sha1";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_max_outpuT_Body_len 0;
upload_pass_form_field "^authenticity_token$|message|dropBox";
upload_cleanup 400 404 499 500-505;
# track uploads in the 'proxied' zone
# remember connections for 30s after they finished
track_uploads proxied 120s;
}
LOCATIOn ~* ^/(send|messages) {
rewrite ^(.*)$/message redirect;
}
LOCATIOn / {
proxy_pass http://mongrel;
proxy_redirect off;
proxy_set_header Host $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 $scheR_383_11845@e;
proxy_read_timeout 120;
proxy_connect_timeout 120;
# track uploads in the 'proxied' zone
# remember connections for 30s after they finished
track_uploads proxied 120s;
}
LOCATIOn @internal_upload {
proxy_pass http://mongrel;
proxy_redirect off;
proxy_set_header Host $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 $scheR_383_11845@e;
proxy_read_timeout 120;
proxy_connect_timeout 120;
}
LOCATIOn ~* ^/send {
rewrite ^(.*)$/message redirect;
}
LOCATIOn ^~ /files/ {
alias /var/data/files/;
chunked_transfer_encoding on;
post_action @protected_done;
if_modified_since off;
gzip off;
internal;
}
LOCATIOn @protected_done {
internal;
proxy_pass http://mongrel;
proxy_set_header RateBytes $body_bytes_sent;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-ForWARDed-For $proxy_add_x_forWARDed_for;
proxy_pass_requesT_Body off;
proxy_pass_request_headers off;
}
LOCATIOn ^~ /images/custom {
alias /var/data/assets/images;
}
LOCATIOn ~* /(javascripts|stylesheets|images)/.*\.(ico|css|gif|js|jp?g|png)(\?[0-9]+)?${
access_log off;
expires 1w;
break;
}
LOCATIOn = /favicon.ico {
alias /var/data/assets/images/favicon.ico;
access_log off;
}
LOCATIOn = /alive {
access_log off;
return 200;
}
LOCATIOn ^~ /progress {
access_log off;
report_uploads proxied;
upload_progress_json_output;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /500.html;
}
}
我对Nginx的经验很少.任何帮助是极大的赞赏.
附加信息:
unicorn.rb
listen '/tmp/unicorn.sock'
worker_processes 2
working_directory "/var/sfta/current"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn.log"
timeout 120
preload_app true
before_fork do |server,worker|
defined?(ActiveRecord::BasE) and
ActiveRecord::Base.connection.disconnect!
old_pid = '/var/run/unicorn.pid.oldbin'
if File.exists?(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
# Throttle the master from forking too quickly by sleeping.
sleep 1
end
after_fork do |server,worker|
defined?(ActiveRecord::BasE) and
ActiveRecord::Base.establish_connection
worker.user('_sfta','_sfta') if Process.euid == 0
end
Unicorn是一个Ruby服务器.您需要使用指定套接字/tmp/unicorn.sock的unicorn启动ruby应用程序.
以上是大佬教程为你收集整理的502错误网关错误Nginx connect()到unix:/tmp/unicorn.sock失败全部内容,希望文章能够帮你解决502错误网关错误Nginx connect()到unix:/tmp/unicorn.sock失败所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。