鍍金池/ 問答/PHP  Linux/ nginx 重寫配置

nginx 重寫配置

在iis上的重寫配置是這樣的

圖片描述

我在nginx上的配置是這樣的,但是除了index.php和/目錄能出來,其他都是file not found 肯定是我配置的問題

location ~^view-(\d+)\.html {
                root           /home/nbjtjc/www.nbjtjc.com;
                rewrite       ^view-(\d+)\.html /index.php?m=v&id=$1 last;
                rewrite       ~^([^?]+).html  "/index.php?m=c&a=$1" last;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }    

        location /view-1022.html {
          root  /home/nbjtjc/www.nbjtjc.com;
          rewrite       ^view-(\d+)\.html /index.php?m=v&id=1022 last;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
          
        }
        location / {
          root  /home/nbjtjc/www.nbjtjc.com;
          rewrite       ^view-(\d+)\.html /index.php?m=v&id=$1 last;
          rewrite       ~^([^?]+).html  /index.php?m=c&a=$1 last;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
          
        }
            
       
        
         location ~* \.php$ {
            root           /home/nbjtjc/www.nbjtjc.com;
            rewrite       ^view-(\d+)\.html /index.php?m=v&id=$1 last;
            rewrite       ~^([^?]+).html  /index.php?m=c&a=$1 last;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~^([^?]+).html {
                root           /home/nbjtjc/www.nbjtjc.com;
                rewrite       ~^([^?]+).html  /index.php?m=c&a={R:1} last;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
        location ~^([^?]+)-page(\d+)\.html {
                root           /home/nbjtjc/www.nbjtjc.com;
                rewrite       ~^([^?]+)-page(\d+)\.html  /index.php?m=c&a={R:1}&page={R:2} last;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }    

各位大神幫我看下吧

回答
編輯回答
小眼睛

你把所有的.html都重寫為index.php?blabla=blabla帶參數(shù)的,但是php代理配置那里匹配的是\.php$這里是不帶參數(shù)的,你要配置成帶參數(shù)的才行。

2017年1月9日 15:08
編輯回答
帥到炸

第一行改為

location ~ ^/view-(\d+)\.html {

試試
還有下面的幾行也不對。

2018年8月9日 11:02