带有proxy_pass和本地静态caching的Nginx不会提供来自代理位置的图像

早上好,

所以,我现在遇到的问题是我想要这个设置工作:

http://qwe1.com/ 

这个请求应该去Apache,并从静态内容文件夹中获取所有的图像,这个configuration工作得很好。


 http://qwe1.com/forum 

这个请求应该被代理到server2(proxy.qwe1.com),现在也工作得很好。


 http://qwe1.com/forum/example.jpg 

这个请求也应该被代理到server2,因为它必须与同一个论坛做,由于静态caching指令,今天不工作。 它匹配静态caching指令,并尝试在磁盘上本地查找映像,并在static.error.log中给出了一个404,您可以在下面看到。 如果我注释掉静态caching指令,我会得到所需的设置,但是我当然想要运行该caching。


我尝试用重写的帮助来分类,到目前为止我已经尝试了这些解决scheme

  location ~* ^(?P<part_uri>/forum/.*\.(css|js|jpg|jpeg|png|swf|gif|svg|ttf|eot))$ { proxy_pass http://proxy.qwe1.com/forum_en$part_uri; proxy_redirect off; proxy_set_header Host $host; access_log /var/log/nginx/TMP.log; error_log /var/log/nginx/TMP.log; } 

这个解决scheme基本上把从http://qwe1.com/forum到http://qwe1.com/的所有东西都转发了出来,但是我没有真正弄清楚为什么,至less这是行不通的。

我也试过这个解决scheme

 rewrite ^(/forum/*\.(css|js|jpg|jpeg|png|swf|gif|svg|ttf|eot))$ /forum_en/$1; location /forum_en { proxy_pass http://proxy.qwe1.com; proxy_redirect off; proxy_set_header Host $host; access_log /var/log/nginx/TMP.log; error_log /var/log/nginx/TMP.log; } 

这与之前的版本具有相同的症状,我从http://qwe1.com/forumredirect到http://qwe1.com/

任何想法的人? 我在这里有整个configuration。 提前致谢。


 ## one.qwe1.com = server1 ## proxy.qwe1.com = server2 server { listen 80; server_name one.qwe1.com; access_log /var/log/nginx/qwe1.com.access.log; error_log /var/log/nginx/qwe1.com.error.log; # proxy /forum to server2 location /forum { proxy_pass http://proxy.qwe1.com/forum_en/; proxy_redirect off; proxy_set_header Host $host; access_log /var/log/nginx/TMP.log; error_log /var/log/nginx/TMP.log; } # static content folders location ~ ^/(images|css|js|fonts) { root /var/www/qwe1.com/current/public; access_log /var/log/nginx/qwe1.com.static.access.log; error_log /var/log/nginx/qwe1.com.static.error.log; } # static content files location ~* \.(css|js|jpg|jpeg|png|swf|gif|svg|ttf|eot)$ { root /var/www/qwe1.com/current/public; access_log /var/log/nginx/qwe1.com.static.access.log; error_log /var/log/nginx/qwe1.com.static.error.log; } # proxy to apache location / { # proxy settings proxy_pass http://127.0.0.1:8080; 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; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } } 

几天前还有类似的问题: 答案 。

概要:
正则expression式比“正常”位置语句具有更高的优先级。
要改变这个,在你的/ forum / location上使用^~修饰符,如下所示:

 location ^~ /forum/ { # proxy_pass to server2 } 

我所做的就是将图像和图像文件夹位置放在根(/)位置下,这样就可以将其整理好,很容易修复。