我想通过Nginx和RoR Web服务器(如Unicorn,Thin或WEBrick)在我的本地计算机上部署我的Ruby on Rails应用程序.如下所示,我想通过post subdomain访问我的网络应用程序:upstream sub {server unix:/tmp/unicorn.subdom...

我想通过Nginx和RoR Web服务器(如Unicorn,Thin或WEBrick)在我的本地计算机上部署我的Ruby on Rails应用程序.
如下所示,我想通过post subdomain访问我的网络应用程序:
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时,每件事情都很完美(我失去了一半的头发才能意识到这一点).为什么以及如何解决?
解决方法:
当您使用端口访问应用程序时 – 您正在直接访问rails服务器,而不是由nginx代理,这适用于调试,但通常不适合生产.
客户端可能不会传递主机头,$host默认为nginx主机
尝试
location @ruby {
proxy_set_header Host $host;
proxy_pass http://sub;
}
和’硬编码’方式:proxy_set_header主机post.subdomain.me;
本文标题为:ruby-on-rails – 为什么我无法通过nginx代理传递访问子域?


- Go Web开发进阶实战(gin框架) 2023-09-06
- R语言关于二项分布知识点总结 2022-11-30
- R语言-如何切换科学计数法和更换小数点位数 2022-11-23
- Swift超详细讲解指针 2023-07-08
- Golang http.Client设置超时 2023-09-05
- Ruby on Rails在Ping ++ 平台实现支付 2023-07-22
- Ruby的字符串与数组求最大值的相关问题讨论 2023-07-22
- Ruby 迭代器知识汇总 2023-07-23
- R语言绘图数据可视化pie chart饼图 2022-12-10
- 汇编语言程序设计之根据输入改变屏幕颜色的代码 2023-07-06