0

I have different problem with nginx rewrite.

In apache I use to htaccess file in root and sub directory.

Use in root folder:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?req=$1 [QSA,L]
</IfModule>

and in subfolder with cp:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ router.php?get=$1 [QSA,L]
</IfModule>

But when i try to configure nginx by this:

but what i try:

server {
    listen      xx.xx.xx.xx:80;
    server_name mydomain.net www.mydomain.net;
    root        /home/admin/web/mydomain.net/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/mydomain.net.log combined;
    access_log  /var/log/nginx/domains/mydomain.net.bytes bytes;
    error_log   /var/log/nginx/domains/mydomain.net.error.log error;

    #first block
    location / {

    if (!-e $request_filename){
        rewrite ^(.+)$ /index.php?req=$1 last;
        }

    }
    #second block    
    location /cp {

    if (!-e $request_filename){
        rewrite ^(.+)$ /router.php?get=$1 last;
        }

    }
}

But when i Try download force php.

This problem not look like other problems i search many about this and I cant find the answer

when I remove second block rewrite work on root.

A1Gard
  • 4,070
  • 4
  • 31
  • 55

1 Answers1

0

For location issue you should check this answer. For processing php you should configure php-fpm and add to nginx configuration php-processing location:

location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME /var/nginx/$fastcgi_script_name;
        fastcgi_index index.php;
    }