部署 为什么 nginx 两个端口访问的是同一个项目

zqalyc · 2013年10月30日 · 最后由 zqalyc 回复于 2013年10月31日 · 4573 次阅读

nginx 配置文件:

upstream app_hyperion {
  server  unix:/tmp/unicorn.hyperion.sock;
}
server {
    listen   9001;
    server_name localhost;
    root       /home/ubuntu/deploy/rhea/public;
    index      index.html;

    location / {
        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;
        try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
    }

    location @ruby {
        proxy_pass http://app_hyperion ;
    }
}
server {
    listen   9002;
    server_name localhost;
    root       /home/ubuntu/deploy/hyperion/public;
    index      index.html;

    location / {
        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;
        try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
    }

    location @ruby {
        proxy_pass http://app_hyperion ;
    }
}

因为配置的是同样的 location

location @ruby {
   proxy_pass http://app_hyperion ;
}
匿名 #2 2013年10月30日

见:http://nginx.org/en/docs/http/ngx_http_core_module.html#location

注意 try_files 配置: try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby; 不存在对应 HTML 文件的 URL 都会 redirect 到@ruby

需要 登录 后方可回复, 如果你还没有账号请 注册新账号