我正在尝试一些我认为相当简单的事情:即将domain.com/dashboard/redirect到另一个(不同的)应用程序,而不是我的主域(这是一个WordPress的安装,但这是相当不相关的,我认为)。
所以当访问domain.com/dashboard/anywhere ,这个第二个应用程序应该像if /dashboard/是域的路由一样,正常处理所有的URL。
我到目前为止所尝试的或者只是导致一个redirect循环,根本没有路由或者给出500错误。
这是迄今为止我的nginx位置的一个例子:
location ~ ^/dashboard/ { alias /srv/www/htdocs/fork/; // this is the second application I want to access rewrite "^(/.*)$" http://domain.com/$1 permanent; index index.php index.html; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; break; }
我试过从alias切换到root ,但无济于事。 而且我不确定接下来要做什么。
有没有人有任何想法可能会导致redirect? (主要是造成domain.com/dashboard/dashboard/dashboard (等)的循环。
更新
好的,下面马克的build议,我已经移动位置块超过任何WordPress的规则,我已经注释了一些代码。 已经取得了进展,现在向domain.com/dashboard/的请求将访问正确的应用程序,但现在正在该应用程序中查找dashboard文件夹。
这是当前的代码:
location ~ ^/dashboard(/)(.*)$ { root /srv/www/htdocs/fork/; break; }
并且当前日志中的错误是"/srv/www/htdocs/fork/dashboard/index.php" is not found (我后来访问/srv/www/htdocs/fork/index.php 。
当/dashboard/foo第一次被击中时,处理就到达rewrite行,在那里它停止处理,并redirect到同一个域的/dashboard ,创build一个循环。
您的其他应用程序可能是Wordpress安装,因为Wordpress包含它自己的重写指令,基本上说,如果任何URL不映射到一个物理文件或目录,而不是传递给Wordpress。 所以,重要的是这些configuration出现在Wordpress重写规则之前。
如果我正确地理解了这种情况,并且这两个应用程序都在同一个域中,那么在这里不需要rewrite指令。 alias指令应足以提供来自不同位置的/dashboard地址。
尝试别名 :
location /dashboard { # you don't need regexps here, naming location will use hash lookup which is much faster alias /srv/www/htdocs/fork/; }