我有 2 个 Rails 应用程序在同一台服务器上运行。我希望对 domain1.com 的请求转发到我的 Rails1 应用程序,并将 domain2.com 请求转发到我的 Rails2 应用程序。我像这样配置了我的 nginx.conf:
upstream thin1 {
server 0.0.0.0:3000;
server 0.0.0.0:3001;
server 0.0.0.0:3002;
}
upstream thin2 {
server 0.0.0.0:3003;
server 0.0.0.0:3004;
server 0.0.0.0:3005;
}
server {
listen 80;
server_name *.domain1.com;
root /path1/;
location / {
try_files $uri/index.html $uri.html $uri @backend;
}
location @backend {
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;
proxy_pass http://thin1;
}
}
server {
listen 80;
server_name *.domain2.com;
root /path2/;
location / {
try_files $uri/index.html $uri.html $uri @backend;
}
location @backend {
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;
proxy_pass http://thin2;
}
}
但是所有请求(domain1.com 和 domain2.com)都会转发到我的 Rails1 应用程序。任何的想法?