如何处理 nginx 重定向到已安装的 Rails 引擎
How to handle nginx redirect to a mounted Rails engine
我有一个 rails 4 应用程序,其引擎安装在单独的域上,如下所示:
mount Test::Engine => '/', as: 'test', constraints: { domain: 'test_engine.com' }
应用程序本身托管在 DigitalOcean Droplet 上。它使用不同的域,比如 application.com
我需要几个域(test_domain1.com、test_domain2.com)才能同时打开 rails 引擎。
我想我会通过配置所有域 DNS A 记录(机器人裸域和 www.*)来指向 Droplet IP 并让 nginx 将它们重定向到 test_engine.com
.
来实现这一点
nginx.conf的要点是:
server {
listen 80;
server_name test_domain1.com www.test_domain1.com test_domain2.com www.test_domain2.com;
return 307 https://test_engine.com$request_uri;
}
server {
listen 80 default_server;
server_name application.com www.application.com;
return 307 https://application.com$request_uri;
}
不幸的是,重定向似乎无法正常工作,例如,访问 www.test_domain1.com
我最终到达 https://application.com
而不是 https://test_engine.com
我意识到这是非常具体的,可能会有更好的解决方案。
在此先感谢您的帮助。
我最终使用正则表达式匹配服务器名称 a-la
server {
listen 80;
server_name ~test_domain;
return 307 https://test_engine.com$request_uri;
}
和使用sudo service nginx restart
而不是sudo service nginx reload
硬重启nginx。
我有一个 rails 4 应用程序,其引擎安装在单独的域上,如下所示:
mount Test::Engine => '/', as: 'test', constraints: { domain: 'test_engine.com' }
应用程序本身托管在 DigitalOcean Droplet 上。它使用不同的域,比如 application.com
我需要几个域(test_domain1.com、test_domain2.com)才能同时打开 rails 引擎。
我想我会通过配置所有域 DNS A 记录(机器人裸域和 www.*)来指向 Droplet IP 并让 nginx 将它们重定向到 test_engine.com
.
nginx.conf的要点是:
server {
listen 80;
server_name test_domain1.com www.test_domain1.com test_domain2.com www.test_domain2.com;
return 307 https://test_engine.com$request_uri;
}
server {
listen 80 default_server;
server_name application.com www.application.com;
return 307 https://application.com$request_uri;
}
不幸的是,重定向似乎无法正常工作,例如,访问 www.test_domain1.com
我最终到达 https://application.com
而不是 https://test_engine.com
我意识到这是非常具体的,可能会有更好的解决方案。 在此先感谢您的帮助。
我最终使用正则表达式匹配服务器名称 a-la
server {
listen 80;
server_name ~test_domain;
return 307 https://test_engine.com$request_uri;
}
和使用sudo service nginx restart
而不是sudo service nginx reload
硬重启nginx。