We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11153
    • 31 Posts
    Hello!

    I had to leave one hosting where I wanted to use Cherokee server behind nginx used as reverse-proxy due to 500 errors.

    Then I moved to my old hosting which also uses nginx as reverse-proxy and Cherokee failed by having port number appended to the URl, like http://domain.com:port/.

    Support told me it’s, probably, due to Cherokee not having support for X-Forwarded-For which is generated by reverse proxy server.

    I was told to try with Lighty, but I experience the same issue despite server’s support for X-Forwarded-For.

    Now, I think the problem is with MODx which seems not to be suitable to be run behind reverse-proxy and, in this case, lighty which is one of supported servers according to http://rtfm.modx.com/display/revolution20/Server+Requirements

    Here is the snippet which handles URL stuff:


    if (!defined('MODX_HTTP_HOST')) {
            if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
                    $http_host='gour-nitai.com:62845';
                    define('MODX_HTTP_HOST', $http_host);
            } else {
                    $http_host= $_SERVER['HTTP_HOST'];
                    if ($_SERVER['SERVER_PORT'] != 80) {
                            $http_host= str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); // remove port from HTTP_HOST
                    }
                    $http_host .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT'];
                    define('MODX_HTTP_HOST', $http_host);
            }
    }
    


    It looks, to me, a bit strange to test $_SERVER[’SERVER_PORT’ twice and it looks it does not handle properly reverse-proxy case where server is indeed running on port != 80.

    Any hint or solution how to use MODx behind reverse-proxy?
      • 11153
      • 31 Posts
      Quote from: gour at Sep 11, 2010, 10:36 AM


      Support told me it’s, probably, due to Cherokee not having support for X-Forwarded-For which is generated by reverse proxy server.

      I was told to try with Lighty, but I experience the same issue despite server’s support for X-Forwarded-For.

      Now, I think the problem is with MODx which seems not to be suitable to be run behind reverse-proxy and, in this case, lighty which is one of supported servers according to http://rtfm.modx.com/display/revolution20/Server+Requirements

      Here is the snippet which handles URL stuff:


      if (!defined('MODX_HTTP_HOST')) {
              if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
                      $http_host='gour-nitai.com:62845';
                      define('MODX_HTTP_HOST', $http_host);
              } else {
                      $http_host= $_SERVER['HTTP_HOST'];
                      if ($_SERVER['SERVER_PORT'] != 80) {
                              $http_host= str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); // remove port from HTTP_HOST
                      }
                      $http_host .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT'];
                      define('MODX_HTTP_HOST', $http_host);
              }
      }
      



      I’ve installed CMS Made Simple 1.8.2, Wordpress-3.0.1 and Joomla-1.5.20 and three packages work behind reverse-proxy and even with Cherokee (not to speak about Lighty), so my conclusion is that the above ’formula’ in MODx’ config.inc.php to handle URLs is too naive and does not cover e.g. lighty (listed as supported server) under reverse proxy. huh huh huh

        • 22303 MODX Staff
        • 10,725 Posts
        The easiest solution for you atm I believe, is to simply define the following system settings in the manager:
        http_host = gour-nitai.com
        site_url = {url_scheme}{http_host}{base_url}
        


        If that doesn’t work, predefine MODX_HTTP_HOST and MODX_SITE_URL with the values you want in your config.core.php files.

        Also, please enter a bug report so this gets addressed in the code as soon as possible. Thanks for reporting your experience with these web servers.
          • 11153
          • 31 Posts
          Quote from: OpenGeek at Sep 11, 2010, 01:51 PM

          The easiest solution for you atm I believe, is to simply define the following system settings in the manager:
          http_host = gour-nitai.com
          site_url = {url_scheme}{http_host}{base_url}
          


          If that doesn’t work, predefine MODX_HTTP_HOST and MODX_SITE_URL with the values you want in your config.core.php files.

          Thank you for workarounds. For now the 2nd method works.

          Also, please enter a bug report so this gets addressed in the code as soon as possible. Thanks for reporting your experience with these web servers.

          I’d like to submit bug report, but Jira requires account. undecided

          Edit: I was finally able to login to the bug tracker and created ticket.