nginx错误500,重写机制中带有斜杠(从apache导入)
我已经得到这个配置文件没有任何重写nginx错误500,重写机制中带有斜杠(从apache导入),apache,.htaccess,mod-rewrite,nginx,url-rewriting,Apache,.htaccess,Mod Rewrite,Nginx,Url Rewriting,我已经得到这个配置文件没有任何重写 server { listen 80; listen [::]:80; root /var/www/testhop.com/www; index index.php index.html index.htm; server_name testhop.com; location / { try_files $uri $uri/ =404; } location ~ \.php$ { try_files $uri =404; fas
server {
listen 80;
listen [::]:80;
root /var/www/testhop.com/www;
index index.php index.html index.htm;
server_name testhop.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我找到了一些进行重写的代码:
try_files $uri $uri/ /index.php?q=$uri&$args;
我已将其修改为最终形式:
server {
(...)
location / {
try_files $uri $uri/ /index.php/$uri&$args;
}
location ~ \.php$ {
(...)
}
但是这个配置给了我500个错误。
我最初的apache重写是:
RewriteRule ^(.*)$ /index.php/$1 [L]
如何使其以index.php/url-params格式工作
?您的
位置~\.php$
块接受以.php
结尾的URI(不包括查询字符串)。通过在.php
之后添加/
,可以添加路径信息
使用此选项应适用于您:
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_PROXY "";
}
位置
正则表达式已更改为接受带有路径信息的URI。try\u files
指令已被替换为,因为在测试文件是否存在之前,需要先拆分URI
我喜欢将include
语句放在任何fastcgi_param
语句之前,以避免后者被静默重写