多个域没有重复配置

时间:2013-07-19 10:28:28

标签: nginx

如何在不复制每个域的服务器{}规则配置的情况下,使用相同的配置为多个域提供服务?

  • example.com
  • example.org
  • example.de
  • example.ro

Nginx配置:

upstream example_live {
    server 127.0.0.1:8300;
}

server {
    listen 80;
    server_name example.com example.org example.de example.ro;
    access_log /var/log/nginx/example.access.log;
    error_log /var/log/nginx/example.error.log;
    location / {
        proxy_pass http://example_live/VirtualHostBase/http/example.??:80/example/VirtualHostRoot/;
        include /etc/nginx/ps.cfg/proxy.conf;
    }
    include /etc/nginx/cfg/base.conf;
}

2 个答案:

答案 0 :(得分:0)

在同一服务器部分,并使用server_name指令支持多个域。似乎你已经给出了上面的答案。

答案 1 :(得分:0)

这对我有用,谢谢你的评论

server_name a.com www.a.com
            b.org www.b.org
            c.net www.c.net;

access_log /var/log/nginx/a.com.access.log;
error_log /var/log/nginx/a.com.error.log;

location / {
    rewrite           ^(.*)$ /VirtualHostBase/http/$http_host:80/a/VirtualHostRoot$1 break;
    proxy_pass        http://127.0.0.1:8080;
}