七.Apache和Nginx规则的对应关系
Apache的RewriteCond对应Nginx的if
Apache的RewriteRule对应Nginx的rewrite
Apache的[R]对应Nginx的redirect
Apache的[P]对应Nginx的last
Apache的[R,L]对应Nginx的redirect
Apache的[P,L]对应Nginx的last
Apache的[PT,L]对应Nginx的last
例如:允许指定的域名访问本站,其他的域名一律转向
Apache:
RewriteCond %{HTTP_HOST} !^(.*?)\.aaa\.com$[NC]
RewriteCond %{HTTP_HOST} !^localhost$
RewriteCond %{HTTP_HOST}!^192\.168\.0\.(.*?)$
RewriteRule ^/(.*)$ [R,L]
Nginx:
if( $host ~* ^(.*)\.aaa\.com$ )
{
set $allowHost ‘1’;
}
if( $host ~* ^localhost )
{
set $allowHost ‘1’;
}
if( $host ~* ^192\.168\.1\.(.*?)$ )
{
set $allowHost ‘1’;
}
if( $allowHost !~ ‘1’ )
{
rewrite ^/(.*)$ ;
}
推荐阅读:
Nginx做负载均衡报:nginx: [emerg] could not build the types_hash
Nginx 负载均衡模块 ngx_http_upstream_module 详述
Nginx+Firebug 让浏览器告诉你负载均衡将请求分到了哪台服务器
Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里