Skip to content

[documentation] Can anyone help with nginx rewrites? #55

Closed

Description

Great looking and educational framework but I'm really struggling here and would appreciate any passing nginxexpers having a look.

I've played with some other basic MVC frameworks and never had the problem where a normal nginx try_file wouldn't work.

So, for example:

location /manage/login {
     try_files $uri $uri/ /manage/login/index.php;
}

But, of course, I can see from the .htaccess and application.php that this uses ?url= GET arguments.

So, 5 hours of reading http://wiki.nginx.org/HttpCoreModule#.24arg_PARAMETER and http://wiki.nginx.org/HttpCoreModule#.24args and http://nginx.org/en/docs/http/converting_rewrite_rules.html I've tried various of the following.... (the install folder is in manage/login

location /manage/login {
try_files $uri $uri/ /manage/login/index.php?url=$uri;
}

also

try_files $uri $uri/ /manage/login/index.php?url=$uri;
try_files $uri $uri/ /manage/login/index.php?url=$args;
try_files $uri $uri/ /manage/login/index.php?url=$uri$args;
try_files $uri $uri/ /manage/login/index.php?$args;

and other combinations of the above. No matter what I put, it always says:

You are in the controller home, using the method index()
You are in the View: application/views/home/index.php

I found another lost soul at http://forum.nginx.org/read.php?2,247614,247647#msg-247647 but again, he wasn't having much luck.

Activity

  1. panique commented on Feb 27, 2014

    @panique
    Owner

    Hey, just for your info: This script uses the most used htaccess in the world, the typical "beautiful URLs" rewrite rules. No weird stuff, no stunts. I even think Wordpress etc. use exactly the same.

    Btw maybe Nginx is not what you should use if this brings you in trouble.

  2. panique commented on Feb 27, 2014

    @panique
    Owner

    He again,

    can you post more info / error logs ? Btw I noticed that you are using a custom folder structure. The php-mvc is build for usage in webroot or in a simple subfolder, so your use case might be special. The php-mvc is btw made for beginners, I think you're quite professional, maybe you don't need he php-mvc. :)

  3. panique commented on Mar 7, 2014

    @panique
    Owner

    I think this ticket is overcomplicating things. The php-mvc is very basic and uses the most standard rewrite rules, and there's no need to install this in nginx in a multi-folder deep nesting structure usually. Running this from two-levels deep subfolders if definitly totally out of the scope of this script, so let's close the ticket.

  4. panique commented on Apr 21, 2014

    @panique
    Owner

    Okay this is a often requested feature, let's create a guideline / native integration for this project! Thanks for the comments so far, good stuff in here!

  5. stevehmig commented on Jul 2, 2014

    @stevehmig

    Hello. I am also having a problem getting this to work on nginx (and switching to Apache is not a realistic option.) I have cloned the repository to /var/www/php-mvc/
    I have made the following changes. 1)modified this line of config.php:
    define('URL', 'http://XXX.XXX.XXX.XXX/php-mvc/');
    where the URL is the ip address of my test DO server.
    2) made the change digitaltoast recommended to /etc/nginx/nginx.conf
    3) made change digitaltoast recommended to /etc/nginx/sites-available/default
    4) restarted the server

    when I go to http://XXX.XXX.XXX.XXX/php-mvc/ the homepage shows up perfectly. But, when I click on the links I get a message saying "file not found."

    I'm not sure how to troubleshoot this.

  6. stevehmig commented on Jul 2, 2014

    @stevehmig

    I changed application.php line 74 to trim, I changed my nginx.conf back to the original. I have this in my /etc/nginx/sites-available/default file:
    location / {
    index index.html index.htm index.php;
    try_files $uri $uri/ /index.php?url=$uri;
    }
    I believe I'm modifying the correct file (/etc/nginx/sites-available/default). If not let me know.
    If it's no trouble, I wouldn't mind looking at your nginx.config file. Thanks!

  7. stevehmig commented on Jul 2, 2014

    @stevehmig

    Thanks, I got it working!
    I changed root /var/www; to:
    root /var/www/php-mvc;
    and in config.php changed:
    define('URL', 'http://XXX.XXX.XXX.XXX/php-mvc/');
    to:
    define('URL', 'http://XXX.XXX.XXX.XXX/');

    I'm not sure if there is a way to get it working my original way, as I have other projects in /var/www/ that I'd want to work on simultaneously. Perhaps this is bad practice, though?

    Thanks again @digitaltoast

  8. RacZo commented on Aug 2, 2014

    @RacZo

    Awesome stuff!

    I just made php-mvc work on Mac OS X 10.10 Beta 4 with NGINX 1.6.0, PHP 5.5.14, PEAR 1.9.5 and MySQL 5.6.16.

    I followed @digitaltoast instructions. Only difference is that I have my sites separated from the main nginx.conf file inside the sites-available folder.

    Here is my /sites-available/phpmvc.com configuration file:

    root       /var/www/phpmvc; 
    server_name  phpmvc.com;
    index   index.html index.htm index.php;
    rewrite_log on;
    error_log    /usr/local/etc/nginx/logs/phpmvc.error.log;
    access_log  /usr/local/etc/nginx/logs/phpmvc.access.log;
    
    location / {
        try_files $uri $uri/ /index.php?url=$uri;
    }
    
    location ~ \.(php)$ {
        try_files      $uri = 404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    

    Added "127.0.0.1 phpmvc.com" to my /etc/hosts file.

  9. panique commented on Aug 2, 2014

    @panique
    Owner

    Cool stuff guys! I'll implement this right into the project in September or October (when there's time!). Good to see that the project is useful for you all :)

  10. panique commented on Oct 14, 2014

    @panique
    Owner

    FYI: #59 has been just merged into develop branch.

  11. changed the title [-]Can anyone help with nginx rewrites?[/-] [+][documentation] Can anyone help with nginx rewrites?[/+] on Oct 17, 2014
  12. panique commented on Nov 8, 2014

    @panique
    Owner

    Heyyyy people,

    I've just released MINI (=php-mvc) in a new version with a different structure (index.php is now in /public, plus diffrenent .htaccess). Would be nice if you could test this and post a working nginx config for this.

    Big thanks!

  13. panique commented on Feb 28, 2015

    @panique
    Owner

    Good news: There's now a nginx config right in the README :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions