
nginx + 승객에서 nginx + 유니콘으로 마이그레이션하는 작업을 진행 중인데 약간 멈춘 지점에 도달했습니다.
테스트 서버를 보려고 하면 404 페이지만 표시됩니다. 내 가상 호스트 구성에 뭔가 문제가 있다고 확신하지만 문제가 무엇인지 알 수 없습니다.
이에 대한 도움을 주시면 대단히 감사하겠습니다.
이것은 내 vhost 파일의 현재 버전입니다.
upstream unicorn-staging {
server unix:/data/appname/staging/current/tmp/sockets/unicorn-staging.sock fail_timeout=0;
}
server {
listen 80 deferred;
listen 443;
ssl on;
root /data/appname/staging/current/public;
server_name foo;
access_log /data/appname/staging/current/log/unicorn-staging-access.log;
error_log /data/appname/staging/current/log/unicorn-staging-error.log;
client_max_body_size 4G;
ssl_certificate /data/appname/staging/shared/certs/appname.crt;
ssl_certificate_key /data/appname/staging/shared/certs/appname.key;
location / {
proxy_pass http://unicorn-staging;
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 https; # for SSL, add this
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
index index.html index.htm;
}
location ~ \.(jpg|png|mp3|ogg)$ {
valid_referers server_names;
if ($invalid_referer) {
return 403;
}
}
location ~ \.(jpg|png|mp3|ogg|js|css|html|gif)$ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location ~ ^/(images|javascripts|stylesheets|assets)/ {
root /data/appname/staging/current/public; # for asset pipeline and other static files
expires max;
break;
}
# redirect server error pages to the stat
error_page 500 502 503 504 /50x.html;
}
답변1
유니콘 구성이 올바르게 설정되지 않았을 가능성이 높습니다.
nginx가 실행 중일 때 내 서버에서 이런 일이 발생하지만 유니콘은 그렇지 않습니다. 그 이유는 nginx가 요청을 소켓에 전달하려고 시도하지만 유니콘이 이를 수신할 수 없기 때문입니다.
기본적으로 유니콘은 포트 8080에서만 수신 대기합니다. 다른 포트나 소켓에서 수신 대기하도록 유니콘 설정을 변경할 수 있습니다.
유니콘 구성 파일( )을 사용하는 경우 config/unicorn.rb
해당 파일 내에 다음과 같은 내용이 있어야 합니다(소켓 경로를 변경해야 합니다).
listen File.expand_path("tmp/sockets/unicorn.sock", RAILS_ROOT)
디버그 목적으로 포트도 수신하도록 설정했습니다.
listen File.expand_path("tmp/sockets/unicorn.sock", RAILS_ROOT)
listen 3000, :tcp_nopush => true
프로덕션 웹 서버에서 유니콘을 시작하려면 다음과 유사한 명령을 실행해야 합니다.
bundle exec unicorn -E production -c config/unicorn.rb
이는 유니콘 구성 파일을 사용합니다. 보다http://unicorn.bogomips.org/Unicorn/Configurator.html예제 구성 파일은 다음과 같습니다.
유니콘 구성 파일을 사용하지 않는 경우 다음 형식의 명령줄 스위치가 필요합니다.
-l, --listen ADDRESS
예를 들어:
bundle exec unicorn -l tmp/sockets/unicorn.sock
pwd
내가 사용하는 경로는 Rails 루트 디렉토리이기 때문에 상대 경로를 사용하고 있습니다 .