从Apache迁移到Nginx时,.htaccess文件中的某些规则必须'转换'为Nginx的配置文件。 一个问题,我似乎无法来解决,一个例子是解释最简单的方法:是否存在与Apaches的{ENV:REDIRECT_STATUS}等效的Nginx环境变量?
请求http://www.domain.com/nginx
在内部被阿帕奇改写为index.php?option=com_content&view=article&id=145
现在我想阻止请求定向到index.php?option=com_content
所以页面仅可通过http://www.domain.com/nginx
以避免重复的内容。在Apache中,这是通过使用这些.htaccess规则实现的:
# Check if it's the first pass to prevent a loop. In case of first pass, the environment variable contains nothing
# If http://www.domain.com/nginx already internally has been rewritten to index.php?option=com_content&view=article&id=145 {ENV:REDIRECT_STATUS} contains '200' and the request is allowed to be processed
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Check if the query string contains requests for the page
RewriteCond %{QUERY_STRING} ^index.php?option=com_content&view=article&id=145 [NC]
# If conditions apply, reject request
RewriteRule .* 404 [L]
在Nginx中,是否有这样一个环境变量,我可以使用? 或者我应该以完全不同的方式来解决这个问题?
编辑1: 在现实生活中,它不仅仅是一个页面,而是一个动态的Joomla网站,有很多页面。我测试其中工程以上,但其意图是阻止在index.php的所有请求option_content &视图=文章& ID = *
编辑2: 这是工作NGINX配置文件:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/domainname;
index index.php index.html index.htm;
server_name domainname.com;
server_name localhost;
location/{
try_files $uri $uri/ /index.php?$args;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
## give 404 header & redirect to custom errorpage without changing URL ##
error_page 404 = /404_custom.php; #global error page, script handles header
error_page 500 502 503 504 /50x.html;
location =/index.php {
set $arg_set "${arg_option}___${arg_view}___${arg_id}";
if ($arg_set ~* "^(((\w|-)+?)___){2}((\w|-)+?)$") {
return 404;
}
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
有指令'内部'http://nginx.org/r/internal –