我对 nginx 了解不深,网上教程也比较乱,现在希望用一个服务器跑两个 rails 项目。
我本来是想修改 upstream 的,但是发现那里已经使用统一的 socks 文件代理了,于是哪里还可以绑定域名呢?
求大神帮助
upstream app {
# Path to Puma SOCK file, as defined previously
server unix:/home/deploy/appname/shared/sockets/puma.sock fail_timeout=0;
}
I imitate a tutorial like this. When I multi my upstream and access public ip, how can nginx rediret to different apps?
I know what you mean.... I just want to know how can nginx rediret to different upstream eg. a.xxx.com goto app1 b.xxx.com goto app2
http {
server {
location / {
proxy_pass http://app1;
}
}
server {
location / {
proxy_pass http://app2;
}
}
}
You mean I should change proxy_pass to the domain I want?
eg. change http://app1 to http://app1.mydomain.com ?
or change listen ports enter listen 80 in the first server and listen 3030 in the second?
啊,各位,我蠢了,配置域名的关键在于 server_name,正确配置如下:
upstream app1{
server unix:/..../puma.sock;
}
upstream app2{
server unix:/.../puma.sock;
}
server{
listen 80;
server_name a.xxx.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://myapp;
}
}
server{
listen 80;
server_name b.xxx.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://myapp2;
}
}
其实根本不需要担心两个 80 端口会冲突什么的,两个项目的运行是用 socks 进行代理的。 决定访问哪个域名去哪里的,最关键的还是 server_name 这一项
自己之前猜想太多,这次一实践立刻就明白了,谢谢@flowerwrong