2016-07-23 71 views
2

Nginx的禁用URL重写我的网址如下nginx的配置改写特定的路径/ URL

location/{ ##merge 
    try_files $uri $uri/ /index.php?q=$uri&$args; 
} 

location /devtools/phpmyadmin/ { ##merge 
    root /var/www/domain.tld/web; 

    location ~ \.php$ { 
     try_files $uri =404; 
     include /etc/nginx/fastcgi_params; 
     fastcgi_pass unix:/var/lib/php5-fpm/web2.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
    } 
} 
/var/www/domain.tld/web/目录

/api/目录,我想禁用URL重写此。因此,如果我想通过url访问index.phphttp://domain.tld/api/index.php/function/method

如何修改nginx配置文件?


编辑:

我尝试以下方法改写,但不工作:

location = /api { 
    rewrite^/api/index.php; 
} 
+0

在第一个“位置”块上方是否存在“root”指令?你在'server'块级有一个'location〜\ .php $'块吗? –

+0

@RichardSmith在第一个位置块之上没有root指令,另一个问题是no - 我从ispconfig编辑nginx配置 – wpdaniel

回答

1

我承认,我不明白您的配置文件。通常,您可以定义一个root以被所有(或大部分)location块继承。通常还有一个独立的location ~ \.php$块来处理通过FastCGI将.php脚本卸载到PHP处理器。

暂时忽略你的location /devtools/phpmyadmin/块,一个典型的实现将是这样的:

root /var/www/domain.tld/web; 

location/{ 
    try_files $uri $uri/ /index.php?q=$uri&$args; 
} 

location ~ \.php$ { 
    try_files $uri =404; 
    include /etc/nginx/fastcgi_params; 
    fastcgi_pass unix:/var/lib/php5-fpm/web2.sock; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_intercept_errors on; 
} 

nginx指令是documented here

如果你想与/api开始使用不同的控制器的URI,您可以添加:

location /api { 
    try_files $uri $uri/ /api/index.php; 
} 

我看不到location /devtools/phpmyadmin/块的用途,因为它似乎并没有增加任何更多的功能。

+0

它的工作原理,谢谢! – wpdaniel