Get the most out of your Centmin Mod LEMP stack
Become a Member

Simple nginx rewrite rule

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by pamamolf, Sep 10, 2016.

  1. pamamolf

    pamamolf Well-Known Member

    2,724
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    6:14 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hi

    It seems that i can't get this rule convert it correct to Nginx rewrite rule:

    Code:
    Redirect 301 /index.php http://www.domain.com/forum/
    any ideas?

    i try this:

    Code:
    location /index.php { rewrite ^(.*)$ http://www.domain.com/forum/ redirect; }
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,175
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,138
    Local Time:
    1:14 AM
    Nginx 1.13.x
    MariaDB 5.5
    wouldn't that end in a redirect loop seeing as index.php is default index file for /forum/ ?

    edit: oh index.php is in main web root and /forum/ is subdirectory !
     
  3. pamamolf

    pamamolf Well-Known Member

    2,724
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    6:14 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Yup that's the issue that i have :(

    Code:
    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
    path of forum is: on forum folder and i want to have a redirect to it....

    I am getting the same also using:

    Code:
    rewrite ^(.*)$ http://www.domain.com/forum/ redirect;
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,175
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,138
    Local Time:
    1:14 AM
    Nginx 1.13.x
    MariaDB 5.5
    Code (Text):
    location / {
      location = /index.php {
        return 302 http://www.domain.com/forum/;
      }
    }
     
  5. pamamolf

    pamamolf Well-Known Member

    2,724
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    6:14 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Not my day :(

    On the first click i am getting 502 error and on the second click 500 internal server day :(
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,175
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,138
    Local Time:
    1:14 AM
    Nginx 1.13.x
    MariaDB 5.5
    nginx debug mode ;) also test in incognito browser as your browser may have permanently cached your previous 301 redirect, hence why you should always test with 302 temp redirects and incognito browser first

    If you have a lot of free disk space, you can enable debug nginx version and compile a nginx debug build of nginx via centmin.sh option NGINX_DEBUG=y centminmod/centmin.sh at 123.08stable · centminmod/centminmod · GitHub

    You can place the option in persistent config /etc/centminmod/custom_config.inc outlined at centminmod.com/upgrade.html#persistent so place in file /etc/centminmod/custom_config.inc
    Code:
    NGINX_DEBUG=y
    then recompile nginx via centmin.sh menu option 4 and then in your nginx error_log directive add debug option A debugging log and restart nginx and check logs

    They will be very very very verbose and lot alot to disk usage logged to error logs, so ensure you have a lot of disk free space.

    You can minimise this by limiting it to specific ip based client connections too
    After debugging is done, reverse the debug now by setting NGINX_DEBUG=n and recompile Nginx again
     
  7. pamamolf

    pamamolf Well-Known Member

    2,724
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    6:14 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    I think the issue is that all files have permissions 777 :(

    How can i convert them all in public folder?

    Thanks
     
  8. eva2000

    eva2000 Administrator Staff Member

    30,175
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,138
    Local Time:
    1:14 AM
    Nginx 1.13.x
    MariaDB 5.5
    Do a find command for files and then directories + chmod them appropriately, though i don't think permissions would cause that problem.
     
    • Agree Agree x 1
  9. pamamolf

    pamamolf Well-Known Member

    2,724
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    6:14 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Now when i click on it first 1-2 times it works and then 502 error but as i test it using host file there is no way to reach any limit or delay to get that....
     
    Last edited: Sep 10, 2016
  10. pamamolf

    pamamolf Well-Known Member

    2,724
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    6:14 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    When it doesn't work i can see a 502 to forum/ and on refresh i can see a forum/ 503 and it works....

    Damn.....
     
  11. eva2000

    eva2000 Administrator Staff Member

    30,175
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,138
    Local Time:
    1:14 AM
    Nginx 1.13.x
    MariaDB 5.5
    nginx debug mode ;)
     
  12. pamamolf

    pamamolf Well-Known Member

    2,724
    243
    63
    May 31, 2014
    Ratings:
    +434
    Local Time:
    6:14 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    It was like a cache issue, don't know after a few restarts and play with rewrite rules it works now :)
     
    • Like Like x 1