<div class="gmail_quote">On Wed, Feb 17, 2010 at 6:58 PM, Maxim Dounin <span dir="ltr">&lt;<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello!<br>
<div class="im"><br>
On Wed, Feb 17, 2010 at 06:40:30PM +0100, Rapsey wrote:<br>
<br>
&gt; What I want is for nginx to serve a file if it can (it exists), if not to<br>
&gt; proxy the request to another server.<br>
&gt; I&#39;m using 0.8.33<br>
&gt;<br>
&gt; server {<br>
&gt;         listen 8080 default;<br>
&gt;         server_name   ~^(www\.)?(?&lt;domain&gt;.+)$;<br>
&gt;         index index.html index.htm;<br>
&gt;<br>
&gt;         if ($host ~* www\.(.*)) {<br>
&gt;           set $host_without_www $1;<br>
&gt;           rewrite ^(.*)$ http://$host_without_www$1 permanent;<br>
&gt;         }<br>
&gt;         location / {<br>
&gt;                 root /var/www/htdocs/$domain;<br>
&gt;                 try_files $uri @def;<br>
&gt;         }<br>
&gt;<br>
&gt;         location ~ \.php$ {<br>
&gt;                 proxy_set_header Host $http_host;<br>
&gt;                 proxy_pass <a href="http://localhost:2000" target="_blank">http://localhost:2000</a>;<br>
&gt;         }<br>
&gt;<br>
&gt;         location @def {<br>
&gt;                proxy_set_header Host $http_host;<br>
&gt;                proxy_pass <a href="http://localhost:9090" target="_blank">http://localhost:9090</a>;<br>
&gt;         }<br>
&gt;     }<br>
&gt; }<br>
<br>
</div>This is not going to work at all since you have an extra &quot;}&quot;.<br>
<div class="im"><br>
&gt; If I run:<br>
&gt; curl -v -H &quot;Host: <a href="http://domain.tv" target="_blank">domain.tv</a>&quot; &quot;<a href="http://server_ip:8080/somefile" target="_blank">http://server_ip:8080/somefile</a>&quot;<br>
&gt;<br>
&gt; The request always gets sent to the server on 9090, even though<br>
&gt; /var/www/htdocs/domain/somefile exists.<br>
&gt; What is wrong with my config?<br>
<br>
</div>According to your config file should be at<br>
/var/www/htdocs/<a href="http://domain.tv/somefile" target="_blank">domain.tv/somefile</a> (note &quot;.tv&quot;).<br>
<br>
Maxim Dounin<br><br></blockquote><div>Ahh I hate regular expressions. Thank you.</div><div>Anyone know how it would have to be formed to only take the middle part of the domain?</div><div><br></div><div><br></div><div>Sergej</div>
<div> </div></div>