我想通过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代理传递访问子域?
基础教程推荐
- R语言使用gganimate创建可视化动图 2022-12-10
- R语言多元线性回归实例详解 2022-12-15
- ruby-on-rails – Nginx支持的Rails应用程序中缺少Content-Length Header 2023-09-20
- R语言histogram(直方图)的具体使用 2022-10-28
- go语言的魔幻旅程14-反射 2023-09-05
- golang 自然语言处理工具(gohanlp) 2023-09-05
- Ruby on Rails在Ping ++ 平台实现支付 2023-07-22
- R语言学习代码格式一键美化 2022-12-05
- Go语言实现一个Http Server框架(二) Server的抽象 2023-07-25
- R语言关联规则深入详解 2022-11-08
