【发布时间】:2017-01-20 10:19:48
【问题描述】:
我有一个 Rails 应用程序在 Digital Ocean 上运行 Unicorn,NGINX 在 Ubuntu 上,我正在尝试处理一堆子域,例如 app1.example.com、app2.example.com 等。
在我的路线中,我正在这样做:
constraints(Subdomain) do
match '/', to: 'pages#landing', via: [:get, :post]
end
这有助于我捕获子域前缀并从控制器显示相应的登录页面。在本地它运行良好,但 NGINX 似乎无论如何都重定向到应用程序的根路径。
这是我的 NGINX 配置:
upstream app_server {
server unix:/var/run/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com *.example.com;
return 301 https://$server_name$request_uri;
}
#When the wildcard above didn't work,
#I tried hardcoding below but still nothing
server {
listen 80;
server_name app1.example.com;
return 301 https://$server_name$request_uri;
}
server {
root /home/rails/example/public;
index index.htm index.html;
listen 443 ssl spdy;
listen [::]:443 ssl spdy;
...
ssl_protocols TLSv1.1 TLSv1.2;
# ssl_ciphers
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
...
resolver 8.8.8.8 8.8.4.4 valid=86400;
resolver_timeout 10;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
我在这里错过了什么?
【问题讨论】:
标签: ruby-on-rails nginx