[英]how to Handle Subdomain in rails with unicorn, and nginx
我在多租戶上遵循了一個簡單的railscasts情節,現在我應用程序中的所有租戶都進入了他們的子域,該子域在我的dev syatem上本地工作,但是由於我在vps系統上嘗試了相同的過程,瀏覽器說找不到服務器。
我已經將域連接到我的IP並修改了我的Nginx文件,但仍然沒有希望
用戶進入其子域后,請求不會到達我的Rails應用。
關於這個的任何想法,否則我可能做對了。 謝謝
我的nginx_unicorn_file
upstream unicorn {
server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}
server {
listen 80 default deferred;
server_name shopnany.com *.shopnany.com;
root <%= current_path %>/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
我這樣做沒有問題。 首先,您需要在使用的任何DNS提供程序中創建A記錄。 例如創建一個DNS記錄:
it.shopnany.com
然后,您必須為此特定部署更新您的nginx配置模板。 可以如下所示:
upstream unicorn_<%= application %> {
server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}
server {
listen 80;
server_name it.shopnany.com;
root <%= current_path %>/public;
location ~ ^/assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn_<%= application %>;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
這對我有用。 現在,我的www及其子域上運行了兩個不同的應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.