nginx 301重定向循环

时间:2014-06-27 12:25:27

标签: nginx php

我遇到了nginx和php-fpm设置问题。 SEO友好的网址不起作用,当我尝试使用直接路由时,我会在浏览器中获得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>

0 个答案:

没有答案