nginx代理
upstream web {
server 127.0.0.1:8787;
keepalive 10240;
}
server {
server_name yoursite.com;
listen 80;
root /www/yoursite/public;
location / {
index index.html;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
if (!-e $request_filename)
{
proxy_pass http://web;
}
}
location = / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://web;
}
}
<pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code><span class="pln">upstream web </span><span class="pun">{</span></code></li><li class="L1"><code><span class="pln"> server </span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">:</span><span class="lit">8787</span><span class="pun">;</span></code></li><li class="L2"><code><span class="pln"> keepalive </span><span class="lit">10240</span><span class="pun">;</span></code></li><li class="L3"><code><span class="pun">}</span></code></li><li class="L4"><code><span class="pln">server </span><span class="pun">{</span></code></li><li class="L5"><code><span class="pln"> server_name yoursite</span><span class="pun">.</span><span class="pln">com</span><span class="pun">;</span></code></li><li class="L6"><code><span class="pln"> listen </span><span class="lit">80</span><span class="pun">;</span></code></li><li class="L7"><code><span class="pln"> root </span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">yoursite</span><span class="pun">/</span><span class="kwd">public</span><span class="pun">;</span></code></li><li class="L8"><code><span class="pln"> location </span><span class="pun">/</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L9"><code><span class="pln"> index index</span><span class="pun">.</span><span class="pln">html</span><span class="pun">;</span></code></li><li class="L0"><code><span class="pln"> proxy_http_version </span><span class="lit">1.1</span><span class="pun">;</span></code></li><li class="L1"><code><span class="pln"> proxy_set_header </span><span class="typ">Connection</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span></code></li><li class="L2"><code><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Real</span><span class="pun">-</span><span class="typ">Ip</span><span class="pln"> $remote_addr</span><span class="pun">;</span></code></li><li class="L3"><code><span class="pln"> proxy_set_header </span><span class="typ">Host</span><span class="pln"> $http_host</span><span class="pun">;</span></code></li><li class="L4"><code><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span></code></li><li class="L5"><code><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Proto</span><span class="pln"> $scheme</span><span class="pun">;</span></code></li><li class="L6"><code><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(!-</span><span class="pln">e $request_filename</span><span class="pun">)</span></code></li><li class="L7"><code><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code><span class="pln"> proxy_pass http</span><span class="pun">:</span><span class="com">//web;</span></code></li><li class="L9"><code><span class="pln"> </span><span class="pun">}</span></code></li><li class="L0"><code><span class="pln"> </span><span class="pun">}</span></code></li><li class="L1"><code><span class="pln"> location </span><span class="pun">=</span><span class="pln"> </span><span class="pun">/</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L2"><code><span class="pln"> proxy_http_version </span><span class="lit">1.1</span><span class="pun">;</span></code></li><li class="L3"><code><span class="pln"> proxy_set_header </span><span class="typ">Connection</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span></code></li><li class="L4"><code><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Real</span><span class="pun">-</span><span class="typ">Ip</span><span class="pln"> $remote_addr</span><span class="pun">;</span></code></li><li class="L5"><code><span class="pln"> proxy_set_header </span><span class="typ">Host</span><span class="pln"> $http_host</span><span class="pun">;</span></code></li><li class="L6"><code><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span></code></li><li class="L7"><code><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Proto</span><span class="pln"> $scheme</span><span class="pun">;</span></code></li><li class="L8"><code><span class="pln"> proxy_pass http</span><span class="pun">:</span><span class="com">//web;</span></code></li><li class="L9"><code><span class="pln"> </span><span class="pun">}</span></code></li><li class="L0"><code><span class="pun">}</span></code></li></ol></pre>