Apache 配置 - 为什么会出现重定向循环?

Apache 配置 - 为什么会出现重定向循环?

我的本地计算机上有 Apache 服务器和 JBoos 服务器以及我的应用程序。

这是我的 Apache 配置:

  • httpd配置文件

    ServerRoot "C:/opt/Apache"
    Listen 80
    
    LoadModule actions_module modules/mod_actions.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule asis_module modules/mod_asis.so
    LoadModule auth_basic_module modules/mod_auth_basic.so
    #LoadModule auth_digest_module modules/mod_auth_digest.so
    #LoadModule authn_alias_module modules/mod_authn_alias.so
    #LoadModule authn_anon_module modules/mod_authn_anon.so
    #LoadModule authn_dbd_module modules/mod_authn_dbd.so
    #LoadModule authn_dbm_module modules/mod_authn_dbm.so
    LoadModule authn_default_module modules/mod_authn_default.so
    LoadModule authn_file_module modules/mod_authn_file.so
    #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
    #LoadModule authz_dbm_module modules/mod_authz_dbm.so
    LoadModule authz_default_module modules/mod_authz_default.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_host_module modules/mod_authz_host.so
    #LoadModule authz_owner_module modules/mod_authz_owner.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule autoindex_module modules/mod_autoindex.so
    #LoadModule cache_module modules/mod_cache.so
    #LoadModule cern_meta_module modules/mod_cern_meta.so
    LoadModule cgi_module modules/mod_cgi.so
    #LoadModule charset_lite_module modules/mod_charset_lite.so
    #LoadModule dav_module modules/mod_dav.so
    #LoadModule dav_fs_module modules/mod_dav_fs.so
    #LoadModule dav_lock_module modules/mod_dav_lock.so
    #LoadModule dbd_module modules/mod_dbd.so
    LoadModule deflate_module modules/mod_deflate.so
    LoadModule dir_module modules/mod_dir.so
    #LoadModule disk_cache_module modules/mod_disk_cache.so
    #LoadModule dumpio_module modules/mod_dumpio.so
    LoadModule env_module modules/mod_env.so
    #LoadModule expires_module modules/mod_expires.so
    #LoadModule ext_filter_module modules/mod_ext_filter.so
    #LoadModule file_cache_module modules/mod_file_cache.so
    #LoadModule filter_module modules/mod_filter.so
    LoadModule headers_module modules/mod_headers.so
    #LoadModule ident_module modules/mod_ident.so
    #LoadModule imagemap_module modules/mod_imagemap.so
    LoadModule include_module modules/mod_include.so
    #LoadModule info_module modules/mod_info.so
    LoadModule isapi_module modules/mod_isapi.so
    #LoadModule ldap_module modules/mod_ldap.so
    #LoadModule logio_module modules/mod_logio.so
    LoadModule log_config_module modules/mod_log_config.so
    #LoadModule log_forensic_module modules/mod_log_forensic.so
    #LoadModule mem_cache_module modules/mod_mem_cache.so
    LoadModule mime_module modules/mod_mime.so
    #LoadModule mime_magic_module modules/mod_mime_magic.so
    LoadModule negotiation_module modules/mod_negotiation.so
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    LoadModule proxy_connect_module modules/mod_proxy_connect.so
    #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
    #LoadModule reqtimeout_module modules/mod_reqtimeout.so
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule setenvif_module modules/mod_setenvif.so
    #LoadModule speling_module modules/mod_speling.so
    LoadModule ssl_module modules/mod_ssl.so
    #LoadModule status_module modules/mod_status.so
    #LoadModule substitute_module modules/mod_substitute.so
    #LoadModule unique_id_module modules/mod_unique_id.so
    #LoadModule userdir_module modules/mod_userdir.so
    #LoadModule usertrack_module modules/mod_usertrack.so
    #LoadModule version_module modules/mod_version.so
    LoadModule vhost_alias_module modules/mod_vhost_alias.so
    
    <IfModule !mpm_netware_module>
    <IfModule !mpm_winnt_module>
    
    User daemon
    Group daemon
    
    </IfModule>
    </IfModule>
    
    
    ServerAdmin example@com
    DocumentRoot "C:/opt/Apache/htdocs"
    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
    </Directory>
    
    <Directory "C:/opt/Apache/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
    <IfModule dir_module>
        DirectoryIndex index.html
    </IfModule>
    
    <FilesMatch "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy All
    </FilesMatch>
    
    ErrorLog "logs/error.log"
    LogLevel warn
    
    <IfModule log_config_module>
         LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
         LogFormat "%h %l %u %t \"%r\" %>s %b" common
         <IfModule logio_module>
               LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
         </IfModule>
         CustomLog "logs/access.log" common
     </IfModule>
    
     <IfModule alias_module>
        ScriptAlias /cgi-bin/ "C:/opt/Apache/cgi-bin/"
     </IfModule>
    
     <IfModule cgid_module>
     </IfModule>
    
     <Directory "C:/opt/Apache/cgi-bin">
         AllowOverride None
         Options None
         Order allow,deny
         Allow from all
     </Directory>
     DefaultType text/plain
    
     <IfModule mime_module>
         TypesConfig conf/mime.types
         AddType application/x-compress .Z
         AddType application/x-gzip .gz .tgz
    
     </IfModule>
    
     # Server-pool management (MPM specific)
     #Include conf/extra/httpd-mpm.conf
    
     # Multi-language error messages
     #Include conf/extra/httpd-multilang-errordoc.conf
    
     # Fancy directory listings
     #Include conf/extra/httpd-autoindex.conf
    
     # Language settings
     #Include conf/extra/httpd-languages.conf
    
     # User home directories
     #Include conf/extra/httpd-userdir.conf
    
     # Real-time info on requests and configuration
     #Include conf/extra/httpd-info.conf
    
     # Virtual hosts
     Include conf/extra/httpd-vhosts.conf
    
     # Local access to the Apache HTTP Server Manual
     #Include conf/extra/httpd-manual.conf
    
     # Distributed authoring and versioning (WebDAV)
     #Include conf/extra/httpd-dav.conf
    
     # Various default settings
     #Include conf/extra/httpd-default.conf
    
     # Secure (SSL/TLS) connections
     #Include conf/extra/httpd-ssl.conf
    
     <IfModule ssl_module>
          SSLRandomSeed startup builtin
          SSLRandomSeed connect builtin
      </IfModule>
    
  • httpd-vhosts.conf

        <VirtualHost *:80>
           ServerName dev.example
           DocumentRoot "C:/opt/Apache/htdocs_dev.example"
    
            <Directory />
                Options FollowSymLinks
                AllowOverride None
                Allow from all
            </Directory>
            ProxyPreserveHost on
            ProxyPass /test-site1 !
            ProxyPass /test-site2 !
    
            ProxyPass / http://localhost:10080/
            ProxyPassReverse / http://localhost:10080/
    
            ErrorLog "logs/dev.example-error.log"
            CustomLog "logs/dev.example-access.log" common
        </VirtualHost>
    
        <VirtualHost *:80>
            ServerName blog.dev.example
            DocumentRoot "C:/opt/Apache/htdocs_blog.dev.example"
            <Directory />
                Options FollowSymLinks
                AllowOverride None
                Allow from all
            </Directory>
            ProxyRequests off
        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>
    
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^blog.*$ [NC]
        RewriteRule ^/author/([^/]+)$ /index/-/c/author/$1 [P,L]
        RewriteCond %{HTTP_HOST} ^blog.*$ [NC]
        RewriteRule ^/tag/([^/]+)$ /index/-/c/tag/$1 [P,L]
        RewriteCond %{HTTP_HOST} ^blog.*$ [NC]
        RewriteRule ^/([^/]+)$ /index/-/c/$1 [P,L]
    
        ProxyPreserveHost on
        ProxyPass /contact !
        ProxyPass / http://localhost:10080/
    
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
        AddOutputFilterByType DEFLATE application/json
    
        ErrorLog "logs/blog.dev.example-error.log"
        CustomLog "logs/blog.dev.example-access.log" common
    </VirtualHost>
    

当我到达http://dev.example在浏览器中一切正常,我进入了应用程序的主站点。但是当我进入http://blog.dev.example我收到有关重定向循环的错误和信息。

我认为我在配置中犯了一些错误。您知道可能是什么问题吗?

编辑:

$ curl -v http://blog.dev.example >/dev/null
* Rebuilt URL to: http://blog.dev.example/
* timeout on name lookup is not supported
*   Trying 127.0.0.1...
* Connected to blog.dev.example (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: blog.dev.example
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Mon, 11 Jul 2016 10:20:41 GMT
< Server: Apache-Coyote/1.1
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1
< X-Powered-By: JSP/2.2
< Location: http://blog.dev.example/
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 216
< Set-Cookie: JSESSIONID=gi821fxux6X2f2Si9kxsPtkK.undefined; Path=/
< Vary: Accept-Encoding
<
* Connection #0 to host blog.dev.example left intact`


$ curl -v http://blog.dev.example/ >/dev/null
* timeout on name lookup is not supported
*   Trying 127.0.0.1...
* Connected to blog.dev.example (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: blog.dev.example
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Mon, 11 Jul 2016 10:32:02 GMT
< Server: Apache-Coyote/1.1
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1
< X-Powered-By: JSP/2.2
< Location: http://blog.dev.example/
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 216
< Set-Cookie: JSESSIONID=9P-1TFJMCMJe0eJUP6cOa3FU.undefined; Path=/
< Vary: Accept-Encoding
<
* Connection #0 to host blog.dev.example left intact

答案1

ProxyPass / http://localhost:10080/
...
RewriteCond %{HTTP_HOST} ^blog.*$ [NC]
RewriteRule ^/([^/]+)$ /index/-/c/$1 [P,L]

我认为它没有重定向到的原因/index/-c/$1是 ProxyPass 在到达 RewriteRule 之前就重定向了。无论路径如何,它总是重定向,因此它永远不会继续到达 RewriteRule。

要修复此问题,您必须将其移至 RewriteRule 之后。

相关内容