We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38304
    • 68 Posts
    Dear Community,

    This is just for fun and learning "better config" purposes... and how its getting done...
    so don't be angry about this lausy attempt.. i am just learning actually...

    i tried the last days to get friendly url working with my nginx Server... Debian (ARM-HF).

    The Server works really well, but i get stuck now with friendly URLS.

    No messages in modx Errorlog.

    In Nginx Errorlog a general:
    2013/02/12 12:49:22 [error] 28958#0: *15 open() "/usr/share/nginx/www/cuisine.html" failed (2: No such file or directory), client: 188.102.250.77, server: cubieboard.no-ip.org, request: "GET /cuisine.html HTTP/1.1", host: "cubieboard.no-ip.org", referrer: "http://cubieboard.no-ip.org/"

    There are no more hints why this happens... Friendly URL seems not to work at all.

    I switched friendly_urls to yes in Systemsettings.

    and i adapted the nginx config (sites-enabled / default) which is available to fpm socket because port isn't supported anymore.

    It looks like this...

    server {
        listen 80;
        server_name cubieboard.no-ip.org;
        root /usr/share/nginx/www;
        index index.php;
        client_max_body_size 30M;
        location / {
            root /usr/share/nginx/www;
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php?q=$1 last;
            }
        }
    
        location ~ \.php$ {
                    try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_ignore_client_abort on;
            fastcgi_param  SERVER_NAME $http_host;
        }
     
        location ~ /\.ht {
            deny  all;
        }
    
    
    location ~*  \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
    expires 1d;
    access_log on;
    }
    
    
    }
    
    


    Also Manager Ressource Pre"View" triggers an 404...

    Maybe someone is out there who has some nginx experience and could give advise how to debug this or get it run finally.

    All in all i am very happy... this modx is running on an Cubieboard and behaving very well... better than i ever expected.

    Would be very great to get this fun work with friendly Urls too...

    Thank you!

    with best regards,
    chris






    This question has been answered by opengeek. See the first response.

    [ed. note: theoretiker last edited this post 13 years, 7 months ago.]
      • 22303 MODX Staff
      • 10,725 Posts
      Try this rather than using if — see If Is Evil.

      location @modx-rewrite {
          rewrite ^/(.*)$ /index.php?q=$1 last;
      }
      location / {
          try_files $uri $uri/ @modx-rewrite;
      }
      
        • 38304
        • 68 Posts
        Thank you Jason for this hint.

        Ok, i changed it the way you advised but i can't see any other behaviour.

        server {
            listen 80;
            server_name localhost;
            root /usr/share/nginx/www;
            index index.php;
            client_max_body_size 30M;
        
            location @modx-rewrite {
               rewrite ^/(.*)$ /index.php?q=$1 last;
            }
        
            location / {
               try_files $uri $uri/ @modx-rewrite;
            }
        
            location ~ \.php$ {
               try_files $uri =404;
               fastcgi_split_path_info ^(.+\.php)(.*)$;
               fastcgi_pass unix:/var/run/php5-fpm.sock;
               fastcgi_index  index.php;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               include fastcgi_params;
               fastcgi_ignore_client_abort on;
               fastcgi_param  SERVER_NAME $http_host;
            }
        
            location ~ /\.ht {
               deny  all;
            }
        
        
            location ~*  \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
               expires 30d;
               access_log off;
            }
        
        
        }
        
        


        Somelike crazy...

        Maybe i missed some Noobie Stuff... Nginx is able to rewrite by default right?

        Thank you, with best regards,
        Chris
          • 38304
          • 68 Posts
          Ok, rewrite is a default module of nginx.... but i noticed following:

          http://cubieboard.no-ip.org/index.php?q=cuisine.html
          works.

          http://cubieboard.no-ip.org/cuisine.html
          doesn't work.

          So it seems the rewrite is not active.

          Is there a shorthand test, for checking if default in sites-enabled is used or overwritten maybe?

          With best regards,
          Chris



            • 22303 MODX Staff
            • 10,725 Posts
            You final location is matching on the html extension and bypassing MODX. Remove html from that list or this will not work.
              • 38304
              • 68 Posts
              Yes, you are right, deleting Contenttype .html solves the Problem.

              Would you please explain, why .html is possible for example in modxcloud then?
              So maybe another more sophisticated rewrite rule there?

              Thank you!

              First step is done!

              with best regards,
              Chris [ed. note: theoretiker last edited this post 13 years, 7 months ago.]
                • 38304
                • 68 Posts
                mmh, sorry but i don't get complete it actually.

                I think
                rewrite ^/(.*)$ /index.php?q=$1 last;
                means,
                redirect everything after the rootdomain to index.php?q=xyz.

                So a call to /cuisine.html will generate a /index.php?q=cuisine.html.

                On my modxcloud account which is based on nginx too, a domain.tld/alias.html is possible without any issues.

                I don't understand why a cusine.html in this call /index.php?q=cuisine.html can overwrite the redirect because PHP has more priority than html in the casses i had in past.

                So, if /cuisine.html bypass the redirect to index.php i have to tell nginx "Don't parse html in first level" just ignore everything with html and parse the rewrite?

                In this case the rewrite rule is not sufficient as it is actually.

                Am I right with this?

                Thank you,
                with best regards
                Chris

                  • 38304
                  • 68 Posts
                  mmh, why this question disappears now... it's not solved yet!
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Did you remove html from this?
                    location ~*  \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
                           expires 30d;
                           access_log off;
                        }

                    You said you deleted the ContentType for .html? You mean in MODX? That would actually break everything...
                      • 38304
                      • 68 Posts
                      Hi Jason,

                      No, i don't removed it from expires rule, because i want the parsed output of modx chached at the users browser too.

                      But yes, i removed now .html Content Type in modx manager, and all i noticed was that i have to call the pages without .html now.

                      You said you deleted the ContentType for .html? You mean in MODX? That would actually [u]break everything... [/u]

                      No, i can't confirm any breaking...
                      Just call cubieboard.no-ip.org ... works really well.. no errors...

                      But i don't want to deliver /welcome because everybody is comfortable with /welcome.html and i think this is the most choosen way.

                      I use Firefox on OSX actually... modx without .html extension works like a charm... no breaking...

                      The question is "The Opposit" of this actual situation.

                      I have to remove the Contenttype .html from modx to get the Nginx rewrite work...
                      i want the opposit... i want a working rewrite with .html extension in modX output.

                      If you think... hey this guy is kidding me... everything impossible...
                      i can give you access via ssh... if you want to have a look....

                      with best regards,
                      Chris