2013-04-24 76 views
0

我有一堆使用.php?id = 123的PHP文件,我需要將它們全部取出。我如何在我的配置文件中完成它們?nginx GET .php變量

我似乎無法弄清楚如何利用

get1.php?id=stuff 
get2.php?id=stuff 
get3.php?id=stuff 

等等...

的問題是我怎麼做,當他們都在相同的根目錄?


用下面我上p.php 500錯誤ID = 945,但PHP工作正常,但我不能登錄或獲取POST數據到工作

server { 
     listen 80; 
     server_name site.com www.site.com; 
     root /home/site/public_html; 
     location/{ 
     index index.php index.html index.htm; 
     location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ { 
     expires 1d; 
     try_files $uri?$args @backend; 
     } 
     error_page 405 = @backend; 
     add_header X-Cache "HIT from Backend"; 
     fastcgi_pass 127.0.0.1:9001; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
     } 
     location @backend { 
     internal; 
     fastcgi_pass 127.0.0.1:9001; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
     } 
     location ~ .*\.(php|jsp|cgi|pl|py)?$ { 
     try_files $uri?$args /index.php; 
     fastcgi_pass 127.0.0.1:9001; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
     } 
     location ~ /\.ht { 
     deny all; 
     } 
    } 

這樣:只是500S 重寫或內部重定向循環而內部重定向到「的index.php」

server { 
    listen  80; 
    server_name site.com www.site.com; 
    root /home/site/public_html; 

    #try and serve static files directly 
    location ~* ^[^\?\&]+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ { 
     try_files $uri @inPlaceDynamicFile; 
     expires 24h; 
     add_header Pragma public; 
     add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 
    } 

    #allow us to have dynamic css/js files 
    location @inPlaceDynamicFile { 
     # examples /css/cssIncludes.css => /css/cssIncludes.css.php 
     try_files $uri.php =404; 

     fastcgi_pass 127.0.0.1:9001; 
     include  fastcgi_params.conf; 
    } 

    location/{ 
     try_files $uri?$args /index.php?q=$uri&$args; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params.conf; 
    } 
} 
+0

btw//.ht應該是「location〜/ \」。{access_log off; log_not_found off;否認一切; }「來阻止所有'隱藏'文件 – Danack 2013-04-24 19:53:17

回答

0

「這是正確的嗎?」

沒有。

1)根不應該在一個位置塊,它應該只在一個服務器塊。

2)用於測試是否存在某個文件的Apache重寫是使用try_files而不是Nginx重寫完成的。 See also

3)您的proxy_pass將傳遞到必須是循環重定向的相同服務器。

4)你在位置塊內也有一個位置塊,這看起來很奇怪。雖然這可能需要一些高級配置,但你不需要它來做你正在做的事情。

我想你可能希望你的nginx的conf是這樣的:

server { 
    listen  80; 
    server_name site.com www.site.com; 
    root /home/site/public_html; 

    #try and serve static files directly 
    location ~* ^[^\?\&]+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ { 
     try_files $uri @inPlaceDynamicFile; 
     expires 24h; 
     add_header Pragma public; 
     add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 
    } 

    #allow us to have dynamic css/js files 
    location @inPlaceDynamicFile { 
     # examples /css/cssIncludes.css => /css/cssIncludes.css.php 
     try_files $uri.php =404; 

     fastcgi_pass 127.0.0.1:9000; 
     include  fastcgi_params.conf; 
    } 

    location/{ 
     try_files $uri /p.php?q=$uri&$args; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params.conf; 
    } 
} 

如果你想包含.PHP去你p.php文件的唯一要求,那麼你應該將其替換的最後一個單元塊:

location ~ /(.*)\.php { 
    try_files $uri /p.php?q=$uri&$args; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include  fastcgi_params.conf; 
} 

location/{ 
    try_files /index.php =404; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include  fastcgi_params.conf; 
} 

編輯

我是否需要爲每個具有 $ _GET [''];的PHP文件創建特定重寫?

沒有 - 你應該能夠通過他們在與像try_files任何文件:

location/{ 
     try_files $uri?$args /index.php?q=$uri&$args; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params.conf; 
    } 

如果它與追加查詢字符串存在,這將匹配任何.PHP請求到PHP文件,然後回退到index.php,如果.php文件不存在同時傳入的查詢字符串和路徑。

+0

我是否需要爲每個具有$ _GET [''];?的PHP文件創建特定的重寫現在,我看起來這真的不是一個.htaccess問題,因爲它是帶有PHP文件的GET – 2013-04-24 18:47:26