我在同一域上托管了针对移动设备和台式机的不同的React应用程序(可以说是静态的)。 因此,我想通过使用nginx检测用户代理来为移动设备和台式机使用单独的目录。
当我访问我的网站时,出现500错误。错误日志中记录的错误是:
4572 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 146.196.34.194, server: m.farespro.com, request....
server {
listen 80;
listen [::]:80;
#root /var/www/html;
#initliaze mobile
set $mobile "";
set $dir "/var/www/html/desktop";
if ($request_uri !~* "^/mobile.*" ){
set $mobile Y;
}
if ($http_user_agent ~* (iPhone|iPod|android|blackberry) ) {
set $mobile "${mobile}E";
}
if ( $http_referer !~* "xxx\.org" ){
set $mobile "${mobile}S";
}
if ( $host ~* "xxx\.org" ){
set $mobile "${mobile}S";
}
if ($mobile = YESS){
set $dir "/var/www/html/mobile";
}
root @dir;
server_name m.farespro.com;
location / {
#try_files $uri $uri/ =404;
try_files $uri /index.html;
}
}