2013-04-24 75 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