nginx 301重定向循环

nginx 301重定向循环,nginx,php,Nginx,Php,我的nginx和php fpm设置有问题。SEO友好的url不起作用,当我尝试使用直接路由时,我会在浏览器中得到301重定向循环 这是nginx配置 # redirect non-www to www server { listen 8081; server_name MYSITEURL.com; rewrite ^(.*) http://www.MYSITEURL.com$1 permanent; } server { listen 8081; server_n

我的nginx和php fpm设置有问题。SEO友好的url不起作用,当我尝试使用直接路由时,我会在浏览器中得到301重定向循环

这是nginx配置

# redirect non-www to www
server {
  listen 8081;
  server_name MYSITEURL.com;
  rewrite ^(.*) http://www.MYSITEURL.com$1 permanent;
}

server {
  listen      8081;
  server_name www.MYSITEURL.com;

  rewrite_log on;

  access_log /var/www/vhosts/MYSITEURL.com/statistics/logs/access_log.nginx combined;
  error_log /var/www/vhosts/MYSITEURL.com/statistics/logs/error_log.nginx warn;

  root /var/www/vhosts/MYSITEURL.com/httpdocs;
  index index.php index.html index.htm default.html default.htm;

    if (!-e $request_filename) {
      rewrite ^(.+)$ /navigation.php?q=$1 last;
    }


    location / {

      try_files $uri $uri/ /navigation.php?q=$uri&$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;
    }

    location ~ \.php$ {
      try_files $uri =404;
      fastcgi_pass  unix:/var/run/php-fpm/www9.sock;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include /etc/nginx/fastcgi.conf;
    }

    location ~ /\. {
      access_log off;
      log_not_found off; 
      deny all;
    }

    location ~* \.(jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js|ico|swf)$ {
      expires max;
      add_header Pragma public;
      add_header Cache-Control "public, must-revalidate, proxy-revalidate";
      access_log off;
      log_not_found off;
    }

  }

  server {
    listen      8081;
    server_name webmail.MYSITEURL.com;
    error_log       /var/log/httpd/webmail.MYSITEURL.com.log warn;

    location / {
      proxy_pass         http://webmail.MYSITEURL.com:8080$request_uri;
      include  /etc/nginx/proxy.conf;
    }

    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|txt|srt|swf|zip|rar|html|htm|pdf)$ {
      root  /usr/share/psa-horde ; 
      expires           7d; 
    }
   }

  server {
    listen      8081;
    server_name sitebuilder.MYSITEURL.com;
    error_log       /var/log/httpd/sitebuilder.MYSITEURL.com.log warn;

    location / {
      proxy_pass         http://MYIP:8080$request_uri;
      include  /etc/nginx/proxy.conf;
    }
   }

  server {
    listen      8081;
    server_name lists.MYSITEURL.com;
    error_log       /var/log/httpd/lists.MYSITEURL.com.log warn;

    location / {
      proxy_pass         http://MYIP:8080$request_uri;
      include  /etc/nginx/proxy.conf;
    }
   }
这是我正在运行的脚本附带的htaccess文件:

Options +FollowSymLinks
RewriteEngine On

AddEncoding gzip .gz
AddEncoding gzip .gzip
<FilesMatch "\.(js.gz|js.gzip)$">
  ForceType text/javascript
</FilesMatch>
<FilesMatch "\.(css.gz|css.gzip)$">
  ForceType text/css
</FilesMatch>


RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/ow_cron/run\.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
apache vhost,正在尝试删除url中端口号的重定向。MYURL.com转到MYURL.com:8081

    <VirtualHost MY.IP.ADDRESS:8080>
            ServerName   MYURL.com:8080
            ServerAlias  www.MYURL.com
            UseCanonicalName Off
            ServerAdmin  "myadmin@email.com"
            DocumentRoot /var/www/vhosts/MYURL.com/httpdocs
            CustomLog  /var/www/vhosts/MYURL.com/statistics/logs/access_log plesklog
            ErrorLog  /var/www/vhosts/MYURL.com/statistics/logs/error_log
    <IfModule mod_userdir.c>
            UserDir /var/www/vhosts/MYURL.com/web_users
    </IfModule>
            <IfModule mod_ssl.c>
                    SSLEngine off
            </IfModule>
            <Directory /var/www/vhosts/MYURL.com/httpdocs>
            <IfModule sapi_apache2.c>
                    php_admin_flag engine on
                    php_admin_flag safe_mode on
                    php_admin_value open_basedir "/var/www/vhosts/MYURL.com/httpdocs:/tmp"
            </IfModule>
            <IfModule mod_php5.c>
                    php_admin_flag engine on
                    php_admin_flag safe_mode on
                    php_admin_value open_basedir "/var/www/vhosts/MYURL.com/httpdocs:/tmp"
            </IfModule>
                    Options -Includes -ExecCGI
            </Directory>
            <Directory /var/www/vhosts/MYURL.com/web_users>
            <IfModule sapi_apache2.c>
                    php_admin_flag engine off
            </IfModule>
            <IfModule mod_php5.c>
                    php_admin_flag engine off
            </IfModule>
            </Directory>
    </VirtualHost>

你能移除“如果”-e$request_filename{rewrite^.+$/navigation.php?q=$1 last;}``部分,看看会发生什么?记住重新启动工作正常的nginx btwyes!非常感谢。我遇到的另一个问题是url中有端口号。mysite.com重定向到mysite.com:8081。你在nginx中看到什么可以做到这一点吗?这上面还有一个apache实例,它可能就在那里,我看不到。那是你唯一的寄宿吗?您可以在命令行上执行netstat-putan以查看nginx正在使用哪些端口吗?tcp 0.0.0.0:8081 0.0.0.0:*LISTEN 21690/nginx.conf在指定的进程下还有大约十行。有一个ApacheVHost在监听8080,还有一个url别名。我会在下一篇评论中发表