1

Recently I changed my webserver from cpanel and CENTOS 7, to use nginx with an scipt called nDeploy, wich works well with wordpress and the sites hosted on my server.

I have this script wich is not working. Because of nginx configuration, my site is using a main index.php to access to most pages, with some php templating solution, but i only get this error: "500 too many redirects"

So here is my .htaccess (when i was using apache, this made the trick):

    Options +FollowSymLinks

RewriteEngine On 
RewriteRule ^([^/]*)\.php$ index.php?page=$1 [L,QSA]

This is my nginx conf file:

# Downloads
rewrite ^/downloads/([0-9]+)/([^/]*)$ /./downloads.php?action=displaycat&catid=$1 last;
rewrite ^/downloads$ /./downloads.php last;

#Knowledgebase
rewrite ^/knowledgebase/([0-9]+)/[a-zA-Z0-9-]+\.html$ /./knowledgebase.php?action=displayarticle&id=$1 last;
rewrite ^/knowledgebase/([0-9]+)/([^/]*)$ /./knowledgebase.php?action=displaycat&catid=$1 last;
rewrite ^/knowledgebase$ /./knowledgebase.php last;


location / {
        try_files $uri $uri/ /index.php?$args;
}

location /NaxsiRequestDenied {
       return 418;
   }

location ~ ^/pingphpfpm$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/opt/remi/php56/root/var/run/user.sock;
}

location ~* /\.(?!well-known\/) { deny all; access_log off; log_not_found off; }
autoindex on;

location ~ \.php$ {
    include /etc/nginx/conf.d/naxsi_learn.rules;
    include /etc/nginx/sites-enabled/mysite.com.nxapi.wl;

    try_files $uri =404;
        fastcgi_pass unix:/opt/remi/php56/root/var/run/extranet.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
}

include /etc/nginx/conf.d/cpanel_services.conf;
# nginx configuration
location / {
rewrite ^/([^/]*)\.php$ /index.php?page=$1 break;
}

And this is my index.php file:

<?php ob_start();
include "inc/config.php";
    $page = $_GET["page"];  
    if(!isset($page) || $page == "" ){ 
        header("Location:".SITE."index.php");
        exit();
    }
    $access = 1;

include "inc/template.php";
ob_flush();
?>

1 Answer 1

0

You have defined two location / blocks which is an error. You should check the error log or test your configuration using nginx -t.

Any URI ending with .php will be processed in the location ~ \.php$ block, which is where you should put your rewrite ... break statement.

For example:

location ~ \.php$ {
    include /etc/nginx/conf.d/naxsi_learn.rules;
    include /etc/nginx/sites-enabled/mysite.com.nxapi.wl;

    rewrite ^/([^/]*)\.php$ /index.php?page=$1 break;

    try_files $uri =404;
    fastcgi_pass unix:/opt/remi/php56/root/var/run/extranet.sock;
    include /etc/nginx/fastcgi_params;
}
2
  • Hi, @Richard Smith, i tried as you said, and still getting the same error. i checked some logs but im not sure about where should i see, in the main directory log nothing show up... and in cpanel error log nothing aswell. Jun 27, 2016 at 14:49
  • I said it didn't work before but... actually it worked, i just changed the conf file inside sites-enabled instead of the copy in my main directory... and it worked... thanks a lot for the help Richard! Jun 27, 2016 at 23:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .