nginx try_files with custom location ^/([0-9]+)

qyzbxkaa  于 5个月前  发布在  Nginx
关注(0)|答案(1)|浏览(62)

我试图运行位置与相同的规则重写
nginx重写

rewrite ^/([0-9]+)$ /post.php?id=$1 ;

字符串
不工作用

location ~ ^/([0-9]+) {
try_files /s.php-$1.txt /s.php?page=$1 ;
root   /home/XX/public_html;
types {}
default_type text/html;
}


如果我添加任何像^/S([0-9]+)这样的单词,它会工作得很好。
但如果没有 S,此规则会损坏所有图像和其他URL

gc0ot86w

gc0ot86w1#

我花了好几年的时间试图修复它,但毫无希望
今天,我发现想法时,看到的方式404与自定义位置

error_page   500 502 503 504 404  /custom.html;
location = /custom.html {
try_files /cachep/index.txt /index.php ;
root   /home/xxx/public_html;
types {}
default_type text/html;
}

字符串
那又怎么样,如果重写工作正常
我们将以同样的方式使用它与位置

rewrite ^/([0-9]+)$ /T$1 ;

location ~ /T([0-9]+) {
try_files /cachep/$1.html /post.php?id=$1 ;
root   /home/xxx/public_html;
expires max;
types {}
default_type text/html;
}


我用

types {}
default_type text/html;


使txt文件像html一样查看
我希望有一天任何一个搜索同样的问题找到它

相关问题