0

I have Apache server and JBoos server with my application on my local computer.

This is my Apache configuration:

  • httpd.conf

    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>
    

When I get to http://dev.example in browser everything is ok and I get home site of my app. But when I get to http://blog.dev.example I get error and information about redirect loop.

I think that I made some mistake in configuration. Do you see what can be wrong?

EDIT:

$ 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
kuba44
  • 101
  • 3
  • please provide output of `curl -v http://blog.dev.example >/dev/null` – Peter Jul 11 '16 at 09:32
  • @Peter I get this: `$ curl -v http://blog.dev.example >/dev/null * Rebuilt URL to: http://blog.dev.example/ * timeout on name lookup is not supported * getaddrinfo(3) failed for blog.dev.example:80 * Couldn't resolve host 'blog.dev.example' * Closing connection 0 curl: (6) Couldn't resolve host 'blog.dev.example' ` – kuba44 Jul 11 '16 at 09:42
  • in your example above, you have changed the real dns to blog.dev.example.com... to post that output, you'll have to put the real dns in there. – Peter Jul 11 '16 at 09:57
  • @Peter so what should I do? – kuba44 Jul 11 '16 at 10:16
  • rerun curl but instead of the fake dns name you gave serverfault "blog.dev.example", fill in the one that works on your dns setup. – Peter Jul 11 '16 at 10:20
  • @Peter sorry :) I see my gaffe:) I post real output in edit. – kuba44 Jul 11 '16 at 10:23
  • ok good. Now see `Location: http://blog.dev.example/` is what it wants you to go to next. It added a "/" on the end of the url you gave, so it has changed. Now repeat curl with the new url, and make a note of each new "Location" header it gives you. Repeat that until you see that it is looping. Then we can use this information to follow the config file to see why it has this result. – Peter Jul 11 '16 at 10:29
  • @Peter As you can see in may last edit, if i send `curl -v http://blog.dev.example/ >/dev/null` I get output with `Location: http://blog.dev.example/` – kuba44 Jul 11 '16 at 10:37

1 Answers1

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

I think the reason it doesn't redirect to /index/-c/$1 is that the ProxyPass just redirects before hitting the RewriteRule. It always redirects regardless of the path, so it never proceeds to the RewriteRule.

To fix it, you have to move it after the RewriteRule.

Peter
  • 2,756
  • 1
  • 20
  • 26
  • I change expresion order, like in my last edit, but it doesn't resolve problem :( – kuba44 Jul 11 '16 at 11:04
  • I would expect that now it should first redirect the client to `/index/-/c/`, and then after that, it will invisibly go to `localhost:10080` which is no longer in this conf file. Is that what it does (test with curl again)? – Peter Jul 11 '16 at 11:08
  • Same situation like before: `curl -v http://blog.dev.example >/dev/null` get ouput with `Location: http://blog.dev.example/` and `curl -v http://blog.dev.example/ >/dev/null` get ouput with `Location: http://blog.dev.example/` too – kuba44 Jul 11 '16 at 11:11
  • well all I can suggest after that is just to try adding test code in your config, for example proxy (with RewriteRule instead of ProxyPass) to a static html page at the top of your config, and move that line down by one line each test until you find out which config line is relevant. Test without the localhost:100080 part too. – Peter Jul 11 '16 at 13:04