我挣扎了几个小时来解决这个问题,但仍然没有用。我在浏览器中看到的错误是:
POST / users 502(Bad Gateway)
我知道这是设置nginx和独角兽的问题,但我无法解决它。顺便说一句,我使用数字海洋部署了我的代码。这是我的配置文件
Unicorn config(nginx.conf
):
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
Unicorn配置文件(/var/nginx/unicorn.conf
):
upstream unicorn {
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
listen 80;
listen 443 ssl;
ssl_certificate /root/certs/server.crt;
ssl_certificate_key /root/certs/server.key;
client_max_body_size 4G;
keepalive_timeout 15;
root /var/www/quoine/current/public;
try_files $uri @unicorn;
location ~ ^/assets|app/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location = /app/ {
rewrite $uri $uri/index.html;
}
location = /app/index.html {
add_header Pragma "no-cache";
add_header Cache-Control "no-cache, no-store, max-age=0, must-revalidate";
add_header Expires "Fri, 01 Jan 1990 00:00:00 GMT";
}
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_pass http://unicorn;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
error_page 500 502 504 /500.html;
location = /500.html {
root /var/www/quoine/current/public;
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /system/maintenance.html break;
}
}
我正在使用Rails 3.如果有人对这个问题有所了解,请告诉我。我花了3个小时没有任何进展。感谢
答案 0 :(得分:0)
你能提供你为独角兽所拥有的配置吗(你提供的文件都是针对nginx的)。它应该是什么样子的一个例子是在这里的“配置服务器”条目的第一部分:https://www.digitalocean.com/community/tutorials/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5
答案 1 :(得分:0)
我试图找出为什么在使用Digital Ocean的一键安装后使用不同版本的Ruby时出现502错误的原因。
我通过查看本指南找到了答案:https://www.digitalocean.com/community/tutorials/how-to-use-the-1-click-ruby-on-rails-on-ubuntu-14-04-image
我的问题是指南中的以下内容:
默认情况下,您拥有正在使用的Ruby位置 更改/ etc / default / unicorn路径名以包含/ usr / local / rvm / rubies 新安装的子文件夹和/ usr / local / rvm / gems子文件夹 版本以及独角兽的位置
希望这有助于帮助某人