Nginx的redirect循环

我试图从一台服务器转移到另一台。 我通常使用apache,但是这个项目使用nginx和Ultimate SEO进行URL修改。 我正在使用相同的nginxconfiguration文件,但我结束了一个redirect循环错误。 以下是site-available中默认文件的内容:

# You may add here your # server { # ... # } # statements for each of your virtual hosts server { listen 80 default; server_name mysitehere.com; access_log /var/log/nginx/mysitehere.access.log; #fastcgi_param DOCUMENT_ROOT /site/public_html/; location / { root /site/public_html/; index index.php index.html index.htm; # rewrite ^/(.*) http://mysitehere.com/$1 permanent; #rewrite ^/index.php?main_page=shopping_cart$ http://mysitehere.com/index.php?main_page=shopping_cart last; if ($host != 'mysitehere.com') { rewrite ^/(.*)$ http://mysitehere.com/$1 last; } if ($host = 'mysitehere.com') { rewrite ^/(.*)$ http://mysitehere.com/$1 last; } # From Ultimate SEO URLs rewrite ^/(.*)-blog-(.*).html$ /index.php?main_page=blogread last; rewrite ^/(.*)-se-(.*).html$ /index.php?main_page=readarticle last; rewrite ^/(.*)-ca-(.*).html$ /index.php?main_page=readarticle last; rewrite ^/blog.html$ /index.php?main_page=blog last; rewrite ^/(.*)-p-(.*).html$ /index.php?main_page=product_info&products_id=$2&$query_string last; rewrite ^/(.*)-ri-(.*).html$ /index.php?main_page=document_general_info&products_id=$2&$query_string last; rewrite ^/(.*)-c-(.*).html$ /index.php?main_page=index&cPath=$2&$query_string} last; rewrite ^/(.*)-m-([0-9]+).html$ /index.php?main_page=index&manufacturers_id=$2&$query_string last; rewrite ^/(.*)-pi-([0-9]+).html$ /index.php?main_page=popup_image&pID=$2&$query_string last; rewrite ^/(.*)-pr-([0-9]+).html$ /index.php?main_page=product_reviews&products_id=$2&$query_string last; rewrite ^/(.*)-pri-([0-9]+).html$ /index.php?main_page=product_reviews_info&products_id=$2&$query_string last; # For Open Operations Info Manager rewrite ^/(.*)-i-([0-9]+).html$ /index.php?main_page=info_manager&pages_id=$2&$query_string last; # For dreamscape's News & Articles Manager rewrite ^/news/?$ /index.php?main_page=news&$query_string last; rewrite ^/news/rss.xml$ /index.php?main_page=news_rss&$query_string last; rewrite ^/news/archive/?$ /index.php?main_page=news_archive&$query_string last; rewrite '^/news/([0-9]{4})-([0-9]{2})-([0-9]{2}).html$ /index.php?main_page=news&date=$1-$2-$3&$query_string' last; rewrite '^/news/archive/([0-9]{4})-([0-9]{2}).html$ /index.php?main_page=news_archive&date=$1-$2&$query_string' last; rewrite ^/news/(.*)-a-([0-9]+)-comments.html$ /index.php?main_page=news_comments&article_id=$2&$query_string last; rewrite ^/news/(.*)-a-([0-9]+).html$ /index.php?main_page=news_article&article_id=$2&$query_string last; # All other pages if (!-f $request_filename) { rewrite ^/(.*).html$ /index.php?main_page=$1&$query_string last; } location ~ /\. { deny all; } } location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|bmp)$ { root /site/public_html; rewrite ^/min/([az]=.*) /min/index.php?$1 last; rewrite ^(.*?)\.v-([^\.]+)\.(js|css)$ $1.$3; access_log off; expires max; } location ~* \.php$ { fastcgi_pass unix:/tmp/php-fpm.sock; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT /site/public_html; fastcgi_param SCRIPT_FILENAME /site/public_html; include fastcgi_params; } # HTTPS error_page 404 /index.php?main_page=page_not_found; } 

我用“mysitehere”取代了实际的url,不然的话也是一样的。 我尝试阅读关于这个问题的其他职位,但不能确定是什么原因导致在这个特定的文件中的错误。 有没有人有任何想法是什么造成这个?

我认为你的问题是这一点的configuration:

  if ($host = 'mysitehere.com') { rewrite ^/(.*)$ http://mysitehere.com/$1 last; } 

请注意,这基本上是将mysitehere.com上的任何URL重写为自己,最后一个指令停止进一步处理。 由于重写的URL以http://开头,因此它指示Nginx执行外部301redirect,而不是内部重写URL,并将该页面作为另一个URL提供。 我只是完全删除这一部分。

如果您还没有这样做,请查看Nginx重写文档以获取详细信息。 阅读并不复杂。