0

如何使用相同的配置为多个域提供服务,而无需为每个域复制 server{} 规则配置?

  • 例子.com
  • 例子.org
  • 例子.de
  • 例子.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;
}
4

2 回答 2

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;
}
于 2013-08-19T06:07:50.297 回答
0

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

于 2013-07-19T10:47:15.343 回答