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

zqalyc · October 30, 2013 · Last by zqalyc replied at October 31, 2013 · 4573 hits

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 ;
}
Unknow user #2 October 30, 2013

见: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

You need to Sign in before reply, if you don't have an account, please Sign up first.