Nginx重写根本不起作用

时间:2022-01-19 11:18:59

I am trying to set up a Piwigo to run on Nginx but I got into some issues with links that should contain and index.php like this: foto.domain.net/index.php/category/3

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

It seems like a simple task, rewriting /index/category/3 to /index.php/category/3, but no matter what I write in those rewrites, I end up with a 404 error and a never changing error log entry that looks like this:

这似乎是一个简单的任务,重写/ 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/"

The error log looks the same even if I add junk to the rewrite line such as:

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

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

So the rewrite part is faulty, somehow but I can't figure it out...

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

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;
	}
}

1 个解决方案

#1


In general terms, as a checklist:

一般而言,作为核对清单:

  • make sure the target/landing URI exists
  • 确保目标/登陆URI存在

  • this should have output "rewrite": nginx 2>&1 | grep -i -o rewrite
  • 这应该有输出“重写”:nginx 2>&1 | grep -i -o重写

  • check your error and access log
  • 检查您的错误并访问日志

#1


In general terms, as a checklist:

一般而言,作为核对清单:

  • make sure the target/landing URI exists
  • 确保目标/登陆URI存在

  • this should have output "rewrite": nginx 2>&1 | grep -i -o rewrite
  • 这应该有输出“重写”:nginx 2>&1 | grep -i -o重写

  • check your error and access log
  • 检查您的错误并访问日志