0

嘿伙计们,我在使用 nginx 代理时遇到了问题。

我想将其设置为将所有请求重定向到一个外部站点(已经有了)。

但是除了域 hg.mydomain.com 上的请求之外,这些请求我想重定向到 localhost:4567(sinatra 应用程序就在那里)

但这不起作用

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";


    server {
       listen       80;
       server_name  *.hg.mydomain.com;

       location / {
            proxy_pass http://127.0.0.1:4567/;
       }
    }

    server {
        listen 80;

        location / {
            proxy_pass http://sb.mydomain.com;
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Shoebox-Host $host;
       }
    }
}
4

1 回答 1

0

If you'd want http://hg.mydomain.com to point to the Sinatra app you would want to change the line

       server_name  *.hg.mydomain.com;

to

       server_name  .hg.mydomain.com;

or

       server_name  hg.mydomain.com;

Also, you might want to add default_server to your listen for the default server. Read more about that here: http://wiki.nginx.org/HttpCoreModule#listen

于 2012-05-11T09:06:11.837 回答