我将我的nginx服务器从0.7.x升级到1.0.2,并且复制了新的nginx服务器的旧configuration文件。 一切工作正常,除了if-指令。 我在旧的configuration文件中有以下的代码块,似乎没有与最新的nginx版本。
location /myapp { if (!-e $request_filename) { rewrite ^/myapp/(.*)$ /myapp/index.php?q=$1 last; break; } root /var/www; index index.php index.html index.htm; }
任何想法有什么不对?
PS:是的,我知道IfIsEvil和我尝试探索try_files,但我无法弄清楚如何传递只有部分的URI后myapp /作为传递inputURI到index.php像这样: try_files $uri index.php?q=$uri
你想把所有的请求redirect到一个通用的前端控制器。
location / { index index.php; try_files $uri $uri/ @handler; ## If missing pass the URI to front handler } location @handler { rewrite / /index.php; # Rewrite for @ErJab: # rewrite ^/myapp/(.*)$ /myapp/index\.php?q=$1 last; } location ~ .php$ { ## Execute PHP scripts fastcgi_pass 127.0.0.1:9000; }