加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Nginx:重写文件的目录路径

发布时间:2020-12-13 21:08:56 所属栏目:Nginx 来源:网络整理
导读:我在这里对Nginx有点新意,所以请耐心等待 我想将foo.bar.com/newfoo?limit=30这样的网址重写为foo.bar.com/newfoo.php?limit=30. 看起来非常简单,像这样重写^([a-z])(.*)$$1.php $2 last; 我感到困惑的部分是放在哪里 我已经尝试了一些位置指令,但我做错了.

我在这里对Nginx有点新意,所以请耐心等待 –

我想将foo.bar.com/newfoo?limit=30这样的网址重写为foo.bar.com/newfoo.php?limit=30.

看起来非常简单,像这样重写^([a-z])(.*)$$1.php $2 last;

我感到困惑的部分是放在哪里 – 我已经尝试了一些位置指令,但我做错了.

这是我现有的虚拟主机配置,我应该在哪里实现我的重写?

server {
listen   80;
listen   [::]:80;

server_name foo.bar.com;
root /home/foo;

index index.php index.html index.htm;

location / {
    try_files $uri $uri/ /index.html;
}

location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}

location ~ .php${
    try_files $uri =404;

    fastcgi_split_path_info ^(.+.php)(/.+)$;
    include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;

}
}

谢谢!

最佳答案
try_files $uri $uri/ $uri.php /index.html;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读