我想通过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代理传递访问子域?
基础教程推荐
- 详解swift中xcworkspace多项目管理 2023-07-05
- R语言的一个加法函数使用介绍 2022-11-14
- 深入探究Golang中log标准库的使用 2023-07-25
- R语言因子型数值转数值型的操作 2022-11-23
- 解决R语言中install_github中无法安装遇到的问题 2022-11-26
- ruby – 如何使用Nginx,Passenger,Sinatra创建多个位置 2023-09-20
- R语言向量下标和子集的使用 2022-12-10
- 汇编语言:比较指令、跳转指令、JCC的使用 2023-07-06
- 如何将mysql数据库文件连接到Rails应用程序上的本地ruby 2023-09-21
- R语言入门使用RStudio制作包含Rcpp代码的R包 2022-12-05
