我正在运行一个Ubuntu 10.04 nginx服务器,用一个反向代理到apache(运行munin监视)。
这是我的默认Apache站点文件的摘录:
<VirtualHost *:8090> ServerAdmin webmaster@localhost DocumentRoot /var/cache/munin/www <Directory /> Options FollowSymLinks AllowOverride None </Directory>
以及我的example.com nginxconfiguration文件的摘录:
location /stats { proxy_pass http://127.0.0.1:8090/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffers 32 4k; }
每当我去到example.com/stats,nginx指向apache通过端口8090,和apache提供了munin网站目录。 它工作很好。
但是如果我想添加另一个域名,例如example.org呢? 我会有另一个nginxconfiguration文件,但我怎么会使Apache的DocumentRoot别的东西? 由于请求是通过本地端口8090从nginx进入apache,apache如何确定请求来自哪个站点以及哪个DocumentRoot /configuration与它一起提供?
我假设我将不得不使用nginx( $host;或$proxy_add_x_forwarded_for;variables?)设置在Apache中的标头…
我在一个nginx.conf文件中运行多个域。 尝试这个:
server { listen xxx.xxx.xxx.xxx:8090; server_name example.org; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://127.0.0.1:8090; } } server { listen xxx.xxx.xxx.xxx:8090; server_name example.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://127.0.0.1:8090; } }
然后在你的apache中添加两个虚拟configuration
<VirtualHost *:8090> ServerName example.org ServerAdmin webmaster@localhost DocumentRoot /var/cache/munin/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <VirtualHost *:8090> ServerName example.com ServerAdmin webmaster@localhost DocumentRoot /var/cache/munin/www2 <Directory /> Options FollowSymLinks AllowOverride None </Directory>