【发布时间】:2021-01-01 05:04:50
【问题描述】:
我很难将此 apache 重写规则转换为 nginx:
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
Options -Indexes
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L,QSA]
</IfModule>
我尝试过的 答:
location / {
try_files $uri $uri/ index.php$is_args$args;
}
乙:
location / {
try_files $uri $uri/ index.phps$args;
}
但是,A 确实为任何 /path 提供 404 错误,而 B 适用于 /path/to/somewhere,但下载 /path。
这是我完整的虚拟主机:
server {
listen 8000;
root /var/www/myphpapp;
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
#autoindex off;
location / {
try_files $uri $uri/ index.php$is_args$args; #A
#try_files $uri $uri/ /index.php?$args; #B
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
所以我想知道正确的 nginx 指令是什么?
【问题讨论】: