$arg_PARAMETER这个变量值为:GET请求中变量名PARAMETER参数的值。
$args 这个变量等于GET请求中的所有参数。
$arg_PARAMETER这个变量值为:GET请求中变量名PARAMETER参数的值。
$args 这个变量等于GET请求中的所有参数。
server { listen 80; server_name afreelyrics.com www.afreelyrics.com; #host跳转到主域名 if ($host != "afreelyrics.com") { rewrite ^(.*) http://afreelyrics.com$1 permanent; } access_log /var/log/nginx/afreelyrics.com/access.log; error_log /var/log/nginx/afreelyrics.com/error.log; root /srv/www_root/afreelyrics.com/web; #优先读取static目录下的静态页 if (-f "${document_root}/static${uri}") { rewrite ^/(.*)$ /static/$uri break; } #lyrics detail,must befor artist detail rewrite ^/([^/]+)/([^/]+)\.html$ /index.php/lyrics/lyrics/$1/$2 break; #artist detail rewrite ^/([^/]+)\.html$ /index.php/artist/artist/$1 break; #search rewrite ^/s/([^/]*)/?$ /index.php/search/index/$1 break; rewrite ^/s-lyrics/([^/]+)(/|/(\d+)\.html?)?$ /index.php/search/lyrics/$1/$3 break; rewrite ^/s-artist/([^/]+)(/|/(\d+)\.html?)?$ /index.php/search/artist/$1/$3 break; #php if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 break; } location ~* \.(js|css|gif|jpeg|jpg|png|ico|bmp)$ { expires 3d; break; } include /etc/nginx/php.conf; } server { listen 80; server_name *.afreelyrics.com; return 404; } #php.conf location ~* \.php($|/) { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SERVER_NAME $server_name; fastcgi_param PATH_INFO $fastcgi_script_name; }
Cygwin安装nginx就不多说了,需要PCRE和zlib,我这安装的1.2.6版本,因为是windows环境,需要修改主配置worker_connections到64以下,超过64会报错,可以用如下方式解决。
关键在于如何加载cgi,老外有个安装php-fpm的文章将的比较详细,也有翻译过来的,那个需要修改多个源码文件,文章具体地址我就懒的再找了,自己搜。这里不用php-fpm,php-cgi.exe就可以实现类似的功能,测试环境性能完全可以忽略了,php-cgi -b :9000 -c D:\Program Files\php-5.3.10-Win32-VC9-x86\php.ini 监听9000端口。 继续阅读
现在有这样一个需求,网站根目录下有静态文件,static目录下也有静态文件,static目录下的静态文件是程序批量生成的,我想让nginx在地址不变的前提下优先使用static目录里面的文件,如果不存在再使用根目录下的静态文件,比如访问首页http://example.com/index.html则nginx返回/static/index.html,如果不存在返回/index.html。
nginx 会对uri中的字符进行解码然后传递给fastCGI,一般情况下也无妨,偏偏我的搜索词中含有反斜杠,编码后的地址
/search/Madmanfoo%2fLovesong/
nginx传递给php的地址就变成了,我用的PATHINFO所以无法得到正确的结果
/search/Madmanfoo/Lovesong/
把nginx官网找了个遍也没找到阻止自动解码的配置,实在不想二次编码,从http://stackoverflow.com/questions/8264239/nginx-unescapes-2f-to-a-forward-slash-how-can-i-stop-it找到了一个类似的帖子,看样只能二次编码了,据说官方就是这么建议的。为了保持地址的美观只对影响PATHINFO的反斜杠进行了二次编码。
$keyword=urlencode($keyword); $keyword=str_replace(array('%2F','%2f'),'%252F',$keyword);
如果有更好的解决办法欢迎指正。