我试图安装我的第一个LEMP堆栈,经过了很多小时的阅读,它工作得很好(该死的,www-data组的写权限问题是一个艰难的问题)。
无论如何,我的Joomla网站现在工作和performance比以往更好,但我注意到一个奇怪的问题,漂亮的url:
如果我访问www.mysite.com/index.php/some/content/alias/一切都很好。 但是,如果我访问www.mysite.com/index.phpsome/content/alias/ (注意index.php之后缺less斜线)也是可以的。
这是预期的行为? 我知道最终用户不会访问那些,但它的存在正在驱使我疯狂,因为它应该扔404,对吧?
这是我的configuration:
server { listen 80; server_name domain.bla; return 301 http://www.domain.bla$request_uri; } server { listen 80; server_name www.domain.bla; root /home/domain/public_html; index index.php index.html index.html; #Specify a charset charset utf-8; # Custom 404 page error_page 404 /404.html; # Include the basic h5bp config set # The error remains if I comment this out, so that's not the problem include h5bp/basic.conf; # Enable PHP-FPM include fastcgi_php.conf; }
fastcgi_php.conf:
location / { try_files $uri $uri/ /index.php?q=$request_uri; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; # fastcgi_intercept_errors on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
…和fastcgi_params:
fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param HTTPS $https if_not_empty; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;
顺便说一句, cgi.fix_pathinfo设置为0。
任何线索? 提前致谢!
这两个URL /index.php?q=$request_uri您的最终try_files子句: /index.php?q=$request_uri
由于该文件不存在,唯一匹配的位置块是“/”。 正则expression式的位置块最初不匹配,因为它不以“.php”结尾,直到被上面提到的try_files指令重写。
另外,你的fastcgi_split_path_info指令也没有做任何事情,因为带有path信息的URL不能匹配那个位置块。