如何在一个端口和一个服务器块中设置具有不同域的nginx

时间:2012-05-22 08:37:52

标签: apache nginx reverse-proxy

我有

server {
    listen 80;
    server_name domain1 domain2 domain3

    location / {
        proxy_pass http://127.0.0.1:8088;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        proxy_connect_timeout   120;
        proxy_send_timeout      120;
        proxy_read_timeout      180;
    }
}

server {
     listen domainX:80;
     server_name domainX www.domainX

     location / {
            proxy_pass http://127.0.0.1:8088;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;

            proxy_connect_timeout   120;
            proxy_send_timeout      120;
            proxy_read_timeout      180;
    }

    location ~* \.(jpeg|jpg|gif|png|ico|bmp|swf|css|js)$ {
            root domainXStaticRoot
    }

    # other options for domainX only
}
来自第一个服务器块nginx的域的

仅返回根页面:

http://domain1 -> returns root page for domain1
http://domain1/style.css -> nginx trying return according location from server block two eg domainXStaticRoot/style.css

如果修改     听80; 至     listen domain1:80; 然后对于domain1一切正常,但我没有找到如何在listen指令中写多个域。

我的错误?

0 个答案:

没有答案