We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37043
    • 1 Posts
    The main error here is the capturing of the first slash.
    Some config changes (i use a similiar config for a modx revo site):

    server {
    	listen 80;
    	server_name www.financetrails.com financetrails.com;
    	root /path/to/www.financetrails.com;
    	index index.php index.html;
    
    	location / {
    		#try to get file directly, try it as a directory or fall back to modx
    		try_files $uri $uri/ @modx;
    	}
    
    	location @modx {
    		#including ? in second rewrite argument causes nginx to drop GET params, so append them again
    		rewrite ^/(.*)$ /index.php?q=$1&$args;
    	}
    
    	location ~ \.php(.*)$ {
    		include fastcgi_params;
    		fastcgi_pass backend;
    		fastcgi_index index.php;
    		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	}
    }


    also make sure you have

    cgi.fix_pathinfo=0


    inside your php.ini, otherwise you might be susceptible to attacks via uploaded php files.
      • 30497
      • 245 Posts
      Hi Roland,

      That did it.

      Thanks a lot for the config.
      • Thanks for posting that Roland.

        As I honestly am not skilled with this server stuff but I suspect others may be looking for this topic at a later stage I linked to it from the Nginx Server Config documentation as an alternative.
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • Has anyone here ran into a "redirect loop" issue with MODx via nginx? ...it's currently only happening for me off the homepage "/", however this is on Evo 1.0.5. with SEO Strict plugin.

          (Not sure if it's related, but thought I'd check here....)

          @Roland, thanks for posting the nginx conf ... good use of try_files and @modx upstream to preserve GET vars. Well done!

          UPDATE:

          Should have thought of this sooner! Simply disabled "Strict URLs" Plugin, and voila! "redirect loop" went away.... (We have our culprit! wink)

          UPDATE 2:

          This issue only showed up as a result of "forced HTTPS" -- Turns out that $_SERVER['HTTPS'] was _not_present in this nginx/php-fpm build $_SERVER vars, while it was there for original Apache setup...

          This resulted in the condition (http://domain.com != https://domain.com) always equating "false", and forcing the redirect (loop) to the HTTPS strict URL.

          The following nginx config adjustment did the trick:

          fastcgi_param HTTPS on;

          [ed. note: pixelchutes last edited this post 12 years, 6 months ago.]
            Mike Reid - www.pixelchutes.com
            MODx Ambassador / Contributor
            [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
            ________________________________
            Where every pixel matters.
          • NOTE: This above solution may become problematic when you _don't_ want HTTPS set to "on".

            By adjusting to the following, you can essentially "set it and forget it":

            Place in the "http" context:

            map $scheme $php_https { default off; https on; }


            See: http://wiki.nginx.org/HttpMapModule

            Then, in your fastcgi_params include, simply reference your new map variable via:

            fastcgi_param HTTPS $php_https;


            :) (Thx kolbyjack in #nginx)
              Mike Reid - www.pixelchutes.com
              MODx Ambassador / Contributor
              [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
              ________________________________
              Where every pixel matters.