<div>It works now. </div>
<div>thanks for your help. </div>
<div> </div>
<div>Nexthop<br><br> </div>
<div><span class="gmail_quote">On 10/12/09, <b class="gmail_sendername">Igor Sysoev</b> &lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Mon, Oct 12, 2009 at 02:43:47AM +0800, quan nexthop wrote:<br><br>&gt; HI:<br>&gt;<br>&gt; Let me give a summary for my question, it is a long descrption.<br>
&gt;<br>&gt;<br>&gt; 1) My question is :<br>&gt; I try to setup the NGINX as a reverse-proxy to protect a WebServer. The<br>&gt; topology is a VirtualHost.<br>&gt; <a href="http://abc.com">abc.com</a> |-----------[nginx reverse proxy] ------- |virtualhost] ----/abc<br>
&gt; directory<br>&gt; <a href="http://123.com">123.com</a>|<br>&gt;         |--/123<br>&gt;  directory<br><br>I still do not understand why you mention /123 directory, however,<br>according sniffed packets, you need something like this:<br>
<br>   server {<br>       server_name  <a href="http://abc.com">abc.com</a>;<br>       location / {<br>           proxy_pass        <a href="http://123.com">http://123.com</a>;<br>           proxy_set_header  $host;<br>       }<br>
   }<br>   server {<br>       server_name  <a href="http://def.com">def.com</a>;<br>       location / {<br>           proxy_pass        <a href="http://123.com">http://123.com</a>;<br>           proxy_set_header  $host;<br>
       }<br>   }<br><br><br>&gt; [note] the virtualhost port is 80<br>&gt;<br>&gt; 2) I got a configuration as the following:<br>&gt;    Add these in NGINX.conf<br>&gt;    server {<br>&gt;        server_name  <a href="http://abc.com">abc.com</a>;<br>
&gt;        location / {<br>&gt;            proxy_pass  <a href="http://123.com/abc/">http://123.com/abc/</a>;<br>&gt;        }<br>&gt;    }<br>&gt;    server {<br>&gt;        server_name  <a href="http://def.com">def.com</a>;<br>
&gt;        location / {<br>&gt;            proxy_pass  <a href="http://123.com/def/">http://123.com/def/</a>;<br>&gt;        }<br>&gt;    }<br>&gt;<br>&gt; 3) When I do according to the above the configuration, I can not access the<br>
&gt; VirtualHost.<br>&gt; I sniff and get the following packet(in Server&#39;s side)<br>&gt;<br>&gt; GET /<a href="http://abc.com">abc.com</a> HTTP/1.0<br>&gt; Host: <a href="http://abc.com">abc.com</a><br>&gt; X-Real-IP: 192.168.2.169<br>
&gt; X-Forwarded-For: 192.168.2.169<br>&gt; Connection: close<br>&gt; Accept: */*<br>&gt; Accept-Language: zh-cn<br>&gt; Pragma: no-cache<br>&gt; If-Modified-Since: Sun, 11 Oct 2009 08:53:36 GMT<br>&gt; If-None-Match: &quot;c8752c52504aca1:2b3&quot;<br>
&gt; User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)<br>&gt; Proxy-Connection: Keep-Alive<br>&gt;<br>&gt; HTTP/1.1 404 Not Found<br>&gt; Content-Length: 1308<br>&gt; Content-Type: text/html<br>&gt; Server: Microsoft-IIS/6.0<br>
&gt; X-Powered-By: <a href="http://ASP.NET">ASP.NET</a><br>&gt; Date: Sun, 11 Oct 2009 09:19:44 GMT<br>&gt; Connection: close<br>&gt; ----------------------------------------------------------------------------------------------------------<br>
&gt; Case 2. Access from 192.168.2.169-&gt;192.168.10.169(web server) *BYPASS* the<br>&gt; NGINX revers proxy<br>&gt;<br>&gt; GET / HTTP/1.1<br>&gt; Accept: */*<br>&gt; Accept-Language: zh-cn<br>&gt; Accept-Encoding: gzip, deflate<br>
&gt; If-Modified-Since: Sun, 11 Oct 2009 08:53:36 GMT<br>&gt; If-None-Match: &quot;c8752c52504aca1:2b3&quot;<br>&gt; User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)<br>&gt; Host: <a href="http://abc.com">abc.com</a><br>
&gt; Connection: Keep-Alive<br>&gt; HTTP/1.1 200 OK<br>&gt; Content-Length: 248<br>&gt; Content-Type: text/html<br>&gt; Content-Location: <a href="http://abc.com/index.htm">http://abc.com/index.htm</a><br>&gt; Last-Modified: Sun, 11 Oct 2009 08:53:36 GMT<br>
&gt; Accept-Ranges: bytes<br>&gt; ETag: &quot;c8752c52504aca1:2c1&quot;<br>&gt; Server: Microsoft-IIS/6.0<br>&gt; X-Powered-By: <a href="http://ASP.NET">ASP.NET</a><br>&gt; Date: Sun, 11 Oct 2009 09:19:34 GMT<br>&gt; --------------------------------------------------------------------------------------------<br>
&gt; At present, I still don&#39;t know how to configure Reverse-Proxy for<br>&gt; VirtualHost.<br>&gt;<br>&gt; please give me a help.<br>&gt;<br>&gt; thanks<br>&gt; NextHop<br>&gt;<br>&gt;<br>&gt;<br>&gt; On 10/11/09, Igor Sysoev &lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt; wrote:<br>
&gt; &gt;<br>&gt; &gt; On Sun, Oct 11, 2009 at 05:55:35PM +0800, quan nexthop wrote:<br>&gt; &gt;<br>&gt; &gt; &gt; Sorry later feedback because of the bussiness trip.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; I configured it according to Igor Sysoev&#39;s advice, but it failed.<br>
&gt; &gt; &gt; I sniff in the webserver&#39;s side, I found the request message is stranger.<br>&gt; &gt; &gt; ----------------------------------------------------------------<br>&gt; &gt; &gt; Case1:  Access from 192.168.2.169-&gt;192.168.10.169(web server) *VIA* NGINX<br>
&gt; &gt; &gt; reverse proxy.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; GET /<a href="http://abc.com">abc.com</a> HTTP/1.0<br>&gt; &gt; &gt; Host: <a href="http://abc.com">abc.com</a><br>&gt; &gt; &gt; X-Real-IP: 192.168.2.169<br>
&gt; &gt; &gt; X-Forwarded-For: 192.168.2.169<br>&gt; &gt; &gt; Connection: close<br>&gt; &gt; &gt; Accept: */*<br>&gt; &gt; &gt; Accept-Language: zh-cn<br>&gt; &gt; &gt; Pragma: no-cache<br>&gt; &gt; &gt; If-Modified-Since: Sun, 11 Oct 2009 08:53:36 GMT<br>
&gt; &gt; &gt; If-None-Match: &quot;c8752c52504aca1:2b3&quot;<br>&gt; &gt; &gt; User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)<br>&gt; &gt; &gt; Proxy-Connection: Keep-Alive<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; HTTP/1.1 404 Not Found<br>
&gt; &gt; &gt; Content-Length: 1308<br>&gt; &gt; &gt; Content-Type: text/html<br>&gt; &gt; &gt; Server: Microsoft-IIS/6.0<br>&gt; &gt; &gt; X-Powered-By: <a href="http://ASP.NET">ASP.NET</a><br>&gt; &gt; &gt; Date: Sun, 11 Oct 2009 09:19:44 GMT<br>
&gt; &gt; &gt; Connection: close<br>&gt; &gt; &gt;<br>&gt; &gt; ----------------------------------------------------------------------------------------------------------<br>&gt; &gt; &gt; Case 2. Access from 192.168.2.169-&gt;192.168.10.169(web server) *BYPASS*<br>
&gt; &gt; the<br>&gt; &gt; &gt; NGINX revers proxy<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; GET / HTTP/1.1<br>&gt; &gt; &gt; Accept: */*<br>&gt; &gt; &gt; Accept-Language: zh-cn<br>&gt; &gt; &gt; Accept-Encoding: gzip, deflate<br>
&gt; &gt; &gt; If-Modified-Since: Sun, 11 Oct 2009 08:53:36 GMT<br>&gt; &gt; &gt; If-None-Match: &quot;c8752c52504aca1:2b3&quot;<br>&gt; &gt; &gt; User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)<br>&gt; &gt; &gt; Host: <a href="http://abc.com">abc.com</a><br>
&gt; &gt; &gt; Connection: Keep-Alive<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; HTTP/1.1 200 OK<br>&gt; &gt; &gt; Content-Length: 248<br>&gt; &gt; &gt; Content-Type: text/html<br>&gt; &gt; &gt; Content-Location: <a href="http://abc.com/index.htm">http://abc.com/index.htm</a><br>
&gt; &gt; &gt; Last-Modified: Sun, 11 Oct 2009 08:53:36 GMT<br>&gt; &gt; &gt; Accept-Ranges: bytes<br>&gt; &gt; &gt; ETag: &quot;c8752c52504aca1:2c1&quot;<br>&gt; &gt; &gt; Server: Microsoft-IIS/6.0<br>&gt; &gt; &gt; X-Powered-By: <a href="http://ASP.NET">ASP.NET</a><br>
&gt; &gt; &gt; Date: Sun, 11 Oct 2009 09:19:34 GMT<br>&gt; &gt; &gt;<br>&gt; &gt; -----------------------------------------------------------------------------------------------------<br>&gt; &gt; &gt; The case 1 is failed. If I bypass the NGINX revers-proxy, it success.<br>
&gt; &gt; &gt; I marked with RED, there are some difference. I can not dig into deep.<br>&gt; &gt; &gt; please help me for the issue.<br>&gt; &gt;<br>&gt; &gt; Then I do not understand, what you meant by this:<br>&gt; &gt;<br>
&gt; &gt; <a href="http://abc.com">abc.com</a> |----[nginx reverse proxy] -- |virtualhost] --/abc directory<br>&gt; &gt; <a href="http://123.com">123.com</a>|<br>&gt; &gt; |--/123  directory<br>&gt; &gt;<br>&gt; &gt; &gt; I pasted the configuration as following:<br>
&gt; &gt; &gt;<br>&gt; &gt; -------------------------------------------------------------------------------<br>&gt; &gt; &gt;  47   server {<br>&gt; &gt; &gt;  48       listen 8080;<br>&gt; &gt; &gt;  49       server_name <a href="http://abc.com">abc.com</a>;<br>
&gt; &gt; &gt;  50       access_log /var/log/nginx/access.log;<br>&gt; &gt; &gt;  51<br>&gt; &gt; &gt;  52       location / {<br>&gt; &gt; &gt;  53           proxy_pass <a href="http://192.168.10.169/abc.com">http://192.168.10.169/abc.com</a>;<br>
&gt; &gt; &gt;  54           proxy_redirect default;<br>&gt; &gt; &gt;  55           proxy_set_header Host $host;<br>&gt; &gt; &gt;  56           proxy_set_header  X-Real-IP  $remote_addr;<br>&gt; &gt; &gt;  57           proxy_set_header X-Forwarded-For<br>
&gt; &gt; $proxy_add_x_forwarded_for;<br>&gt; &gt; &gt;  58           client_max_body_size 50m;<br>&gt; &gt; &gt;  59           client_body_buffer_size 256k;<br>&gt; &gt; &gt;  60      }<br>&gt; &gt; &gt;  61  }<br>&gt; &gt; &gt;  62  server {<br>
&gt; &gt; &gt;  63       listen 8080;<br>&gt; &gt; &gt;  64       server_name <a href="http://def.com">def.com</a>;<br>&gt; &gt; &gt;  65       access_log /var/log/nginx/access.log;<br>&gt; &gt; &gt;  66<br>&gt; &gt; &gt;  67       location / {<br>
&gt; &gt; &gt;  68           proxy_pass <a href="http://192.168.10.169/def.com">http://192.168.10.169/def.com</a>;<br>&gt; &gt; &gt;  69           proxy_redirect default;<br>&gt; &gt; &gt;  70           proxy_set_header Host $host;<br>
&gt; &gt; &gt;  71           proxy_set_header  X-Real-IP  $remote_addr;<br>&gt; &gt; &gt;  72           proxy_set_header X-Forwarded-For<br>&gt; &gt; $proxy_add_x_forwarded_for;<br>&gt; &gt; &gt;  73           client_max_body_size 50m;<br>
&gt; &gt; &gt;  74           client_body_buffer_size 256k;<br>&gt; &gt; &gt;  75     }<br>&gt; &gt; &gt;  76  }<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; thanks<br>&gt; &gt; &gt; NextHop<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; On 10/6/09, Igor Sysoev &lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt; wrote:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; On Mon, Oct 05, 2009 at 04:00:23PM +0800, quan nexthop wrote:<br>
&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; Hi all:<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; I try to setup the NGINX as a reverse-proxy to protect several<br>&gt; &gt; &gt; &gt; webservers,<br>&gt; &gt; &gt; &gt; &gt; which lots of websites are running on. Yes, it is a virtual host :)<br>
&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; <a href="http://abc.com">abc.com</a> |-----------[nginx reverse proxy] ------- |virtualhost]<br>&gt; &gt; ----/abc<br>&gt; &gt; &gt; &gt; &gt; directory<br>&gt; &gt; &gt; &gt; &gt; <a href="http://123.com">123.com</a>|<br>
&gt; &gt; &gt; &gt; &gt; |--/123  directory<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; [note] the virtualhost port is 80.<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; I go through the <a href="http://wiki.nginx.net">wiki.nginx.net</a> and can not find any configuration<br>
&gt; &gt; &gt; &gt; related<br>&gt; &gt; &gt; &gt; &gt; with the topology.<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; Any one can paste a configuration for such case?<br>&gt; &gt; &gt; &gt; &gt; how can I distinguish the different server in one listening port?<br>
&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Probably you need<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;    server {<br>&gt; &gt; &gt; &gt;        server_name  <a href="http://abc.com">abc.com</a>;<br>&gt; &gt; &gt; &gt;        location / {<br>
&gt; &gt; &gt; &gt;            proxy_pass  <a href="http://123.com/abc/">http://123.com/abc/</a>;<br>&gt; &gt; &gt; &gt;        }<br>&gt; &gt; &gt; &gt;    }<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;    server {<br>&gt; &gt; &gt; &gt;        server_name  <a href="http://def.com">def.com</a>;<br>
&gt; &gt; &gt; &gt;        location / {<br>&gt; &gt; &gt; &gt;            proxy_pass  <a href="http://123.com/def/">http://123.com/def/</a>;<br>&gt; &gt; &gt; &gt;        }<br>&gt; &gt; &gt; &gt;    }<br>&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; --<br>&gt; &gt; &gt; &gt; Igor Sysoev<br>&gt; &gt; &gt; &gt; <a href="http://sysoev.ru/en/">http://sysoev.ru/en/</a><br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt;<br>
&gt; &gt; --<br>&gt; &gt; Igor Sysoev<br>&gt; &gt; <a href="http://sysoev.ru/en/">http://sysoev.ru/en/</a><br>&gt; &gt;<br>&gt; &gt;<br><br>--<br>Igor Sysoev<br><a href="http://sysoev.ru/en/">http://sysoev.ru/en/</a><br><br>
</blockquote></div><br>