【发布时间】:2016-03-16 14:52:37
【问题描述】:
我想通过Nginx 和RoR Web 服务器(如Unicorn、Thin 或WEBrick)在我的本地计算机上部署我的Ruby on Rails 应用程序。
如下图,我想通过post子域访问我的web-app:
upstream sub {
server unix:/tmp/unicorn.subdomain.sock fail_timeout=0;
# server 127.0.0.1:3000;
}
server {
listen 80;
server_name post.subdomain.me;
access_log /var/www/subdomain/log/access.log;
error_log /var/www/subdomain/log/error.log;
root /var/www/subdomain;
index index.html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
}
location @ruby {
proxy_pass http://sub;
}
}
一切正常,当我输入 post.subdomain.me 时,我可以看到我的 RoR 应用程序。
问题:当我使用post.subdomain.me url 时,我无法访问我的子域(request.subdomain 返回空,request.host 返回subdomain instaed of subdomain.me)。但是当我使用post.subdomain.me:3000 时,一切都很完美(我失去了一半的头发才意识到这一点)。为什么以及如何解决?
【问题讨论】:
-
你用什么做HTTP服务器?您提到了 Unicorn、Thin 和 Webrick,但没有说明您尝试了哪一种。
-
@TomL:所有这些我都有同样的问题。
-
您所有的
proxy_xxx指令都位于错误的location块中。您需要将它们与location @ruby块中的proxy_pass指令一起保留,否则它们将被忽略。 -
@RichardSmith:您能否详细描述一下您的回答?
标签: ruby-on-rails ubuntu nginx unicorn