We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30058
    • 8 Posts
    Hi, gurus
    Can’t find the answer why modx index.php doesn’t want to open up my resource. i’ve checked this by slightly modifying index.php:
    print_r($_GET)


    results in: Array ( [q] => /mixture.html ) 1

    Still nothing. Moreover i’ve inserted link like [[~3]] inside my resource which was translated to alias.html on the page. Still 404 in nginx logs. What can be wrong with my MODx?
    • What does your nginx rewrite configuration for this look like? MODx will not do friendly URL handling without a rewrite engine.
        • 30058
        • 8 Posts
        Quote from: OpenGeek at Jun 17, 2010, 12:26 PM

        What does your nginx rewrite configuration for this look like? MODx will not do friendly URL handling without a rewrite engine.
        i intentionally have written the print_r($_GET) from index.php output smiley isn’t it enough to prove that nginx rewrites are acting as expected? though here’s the fragment of my nginx.conf:
        location / {
        	root /var/www/mysite/docs;
        	index index.php index.html;
        	
        	#if (-f $request_filename){
        	#    expires 10d;
        	#    break;
        	#}
        	
        	#if (-d $request_filename){
        	#    break;
        	#}
        
        	if (!-e $request_filename){
        	    rewrite ^(.+)$ /index.php?q=$1 last;
        	}
         }
            location ~ .php$ {
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   backend;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/mysite/docs$fastcgi_script_name;
                
                include fastcgi_params;
                fastcgi_param  QUERY_STRING     $query_string;
                fastcgi_param  REQUEST_METHOD   $request_method;
                fastcgi_param  CONTENT_TYPE     $content_type;
                fastcgi_param  CONTENT_LENGTH   $content_length;
                fastcgi_param DOCUMENT_URI      $document_uri;
                fastcgi_param DOCUMENT_ROOT     /var/www/mysite/docs;
                
                fastcgi_intercept_errors        on;
                fastcgi_ignore_client_abort     off;
                fastcgi_connect_timeout 60;
                fastcgi_send_timeout 180;
                fastcgi_read_timeout 180;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
            }
        
          • 30058
          • 8 Posts
          Nobody knows the answer? :-( Should i revert to Evo then? :-(
          • Quote from: timteka at Jun 17, 2010, 02:47 PM

            Nobody knows the answer? :-( Should i revert to Evo then? :-(
            This has nothing to do with Evo vs. Revo AFAIK. I have no idea what the problem is without additional information. Anyone else running Revo on nginx that can see anything wrong with these rewrite rules?
              • 26916
              • 2 Posts
              I did the research to find out how to troubleshoot nginx rewrite rules, and figured out a set of rules that work:

              server {
                  listen       80;
                  server_name  myModxSite.com;
                  rewrite   ^  http://www.myModxSite.com$request_uri?;
              }
              
              server {
                  listen       80;
                  server_name  www.myModxSite.com;
              
                  #root /www/myModxSite.com/root-down/;
                  root /www/myModxSite.com/root/;
              
                  access_log  logs/myModxSite.com.access.log;
                  error_log  logs/myModxSite.com.error.log;
              
              # To debug rewrites, uncomment the following two lines
                  #error_log  logs/myModxSite.com.error.log notice;
                  #rewrite_log on;
              
                  location = /favicon.ico     { return 204; }
                  location = /favicon.png     { }
              
                  # serve static files directly
                  location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ {
                      access_log        off;
                      expires           30d;
                      break;
                  }
                  location = /index.php {
                      include fastcgi_params.modx;
                  }
                  location / {
                      index index.php;
              
                      if (!-e $request_filename) {
                          rewrite ^/(.*)$ /index.php?q=$1 last;
                      }
                  }
              }
              


              The main change is getting the initial leading "/" out of the passed query in
              rewrite ^/(.*)$ /index.php?q=$1 last;
              • Great! I’m bookmarking this; I’ve been meaning to start experimenting with nginx ever since I had to upgrade my VPS when I started having out-of-memory problems with two active sites running.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                • Thanks for the information and contribution shaneholloway!
                    • 2364
                    • 73 Posts
                    Thanks, very helpful. But I have just one note about. "If" statements in nginx config are very not recommended (example).
                    I use somesing like:
                        location / {
                            try_files $uri $uri/ @rewrite;
                        }
                        location @rewrite {
                            rewrite ^/(.*)$ /index.php?q=$1;
                        }
                    

                    The ideal solution is
                        location / {
                            try_files $uri $uri/ /index.php?q=$uri&$args;
                        }
                    

                    but in this case furls not working because $uri contain "/" at the beginning (index.php?q=/some/page.html) which is not handling by MODx.
                    BTW, APC problem was solved with ’fastcgi_param PHP_VALUE "apc.cache_by_default=0"’ for me.
                      • 22079
                      • 5 Posts
                      Hmmm, trying different setup, look at

                      http://modxcms.com/forums/index.php?topic=35708.0

                      But still getting 404 sad