doudouwen2763 2013-10-20 19:15
浏览 203
已采纳

仅当Nginx不存在文件时,才将URL重定向到PHP

I am trying to get Nginx to rewrite URL space ./data/(.+).png to serveImage.php?guid=$1

server {
    server_name my.server;
    listen 80;
    listen 127.0.0.1:80;
    root /var/www/my.server;
    index index.html;

    location / {
        try_files $uri $uri/ index.html;
        rewrite ^/data/(.+).png serveImage.php?guid=$1 last;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
}

What am I doing wrong? serveImage.php does exist in the document root.

  • 写回答

2条回答 默认 最新

  • dounai6613 2013-10-20 19:44
    关注

    Rewriting did not seem to work as planned (nothing that appeared to access.log or error.log gave even a hint that the rule was even caught). I made a more generic router that might fit better the other yet unknown needs as well.

    location / {
        try_files $uri $uri/ @router;
        index index.html index.php;
        error_page 403 = @router;
        error_page 404 = @router;
    }
    
    location @router {
        rewrite ^(.*)$ /router.php?$1;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?