Nginx重写根本不起作用

时间:2015-05-04 01:09:06

标签: mod-rewrite nginx url-rewriting rewrite

我正在尝试设置一个在Nginx上运行的Piwigo,但是我遇到了一些问题,包含应该包含的链接和index.php,如下所示: 的 foto.domain.net/index.php/category/3

这似乎是一个简单的任务,将 / index / category / 3 重写为 /index.php/category/3 ,但不管我在那些重写中写的是什么,我最终得到一个404错误和一个永远不会改变的错误日志条目,如下所示:

open() "/srv/http/foto/index/category/3" failed (2: No such file or directory), client: 94.242.246.23, server: ~^(?<prefix>www)?\.?(?<subdomain>[a-z]+)?\.domain\.net$, request: "GET /index/category/3 HTTP/1.1", host: "foto.domain.net", referrer: "http://foto.domain.net/"

即使我将垃圾添加到重写行,错误日志看起来也是一样的,例如:

rewrite ^/index((/|$).*)$ /JUNK_index.php$1 last;

所以重写部分有问题,不知怎的但是我无法弄清楚......

&#13;
&#13;
server {
    listen       80;
    server_name  domain.net;
    return       301 $scheme://www.domain.net$request_uri;
}

server {
	listen 80;
	server_name "~^(?<prefix>www)?\.?(?<subdomain>[a-z]+)?\.domain\.net$";
	root /srv/http/$subdomain;

	location @rewrites {
   		rewrite ^/picture((/|$).*)$ /picture.php$1 last;
   		rewrite ^/index((/|$).*)$ /index.php$1 last;
   		# The following is needed for batch operations which use i.php
   		rewrite ^/i((/|$).*)$ /i.php$1 last;
	}

	location /$subdomain {
   		index index.php index.html;
   		try_files $uri $uri.php $uri/ @rewrites;
	}
	
	location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
   		try_files $script_name = 404;
   		fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
   		fastcgi_param PATH_INFO $path_info;
   		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   		include fastcgi_params;
	}
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:-1)

一般而言,作为清单:

  • 确保目标/着陆URI存在
  • 这应该具有输出“ rewrite”:nginx 2>&1 | grep -i -o重写
  • 检查您的错误并访问日志