Conversion .htaccess to NGINX — how?

Hello everybody! Is the root of the site, in it two folders
app
and
public
nearby lies .htaccess with the code
RewriteEngine on
RewriteRule ^(.*) public/$1 [L]

Folder app has files of Apache
In the folder public it code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

here is the file index.php
In the script code is integrated with the CNC. Because all of this cereal provided for Apache, I can't make a working config
The most working variant
spoiler
server {
 listen 127.0.0.1:80;
 server_name localhost;

 root home/localhost/public_html;

 index index.php index.html;

 log_not_found off;
 access_log logs/localhost-access.log main;

 charset utf-8;

 #convert htaccess
 location / {
 rewrite ^/(.*) /public/$1 break;
}

 location /public/ {
 if (-e $request_filename){
 rewrite ^(.*)$ /public/$1 break;
}
 rewrite ^(.*)$ /index.php?url=$1 break;
}
 #convert htaccess

 location ~ /\. { deny all; }
 location = /favicon.ico { }
 location = /robots.txt { }

 location ~ \.php$ {
 location 127.0.0.1:9071;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
 include fastcgi_params;
}

}

but it is not working the CNC and the failure of one static file, although the path is correct.
Google has been used docks were read. I hope for your help.
March 19th 20 at 09:06
2 answers
March 19th 20 at 09:08
Solution
server {
 listen 127.0.0.1:80;
 server_name localhost;

 root /home/localhost/public_html/public;

 index index.php;

 log_not_found off;
 access_log logs/localhost-access.log main;

 charset utf-8;

 location / {
 try_files $uri $uri/ @php;
}

 location @php {
 rewrite ^/(.*) /index.php?url=$1;
}

 location ~ /\. { deny all; }
 location = /favicon.ico { }
 location = /robots.txt { }

 location ~ \.php$ {
 location 127.0.0.1:9071;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
}

}
Thanks for the reply.
When "stupid copying" - came the error "No input file specified."
just remembered a similar case was SCRIPT_FILENAME
#from your example
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

drew attention to the lack of backslash $document_root$ / fastcgi_script_name why?
also tried instead of $document_root$/fastcgi_script_name - $request_filename; the result is the same - No input..
root /home/localhost/public_html/public; here you also added a slash, now he is useful:D (now in his absence get a 403) I forgot to mention that everything happens locally on Winginx.
In any case, thank you! Would have guessed correctly use try_files and @. Will now Google "No input file specified." - Ruthe.Von96 commented on March 19th 20 at 09:11
UPD. In the future I am going to combine this config for combat host nginx+php-fpm - Ruthe.Von96 commented on March 19th 20 at 09:14
@hcodeorg, you need to specify the root. Paths in a configuration file must be specified in UNIX style, using forward slashes C:/web/html;
nginx.org/ru/docs/windows.html
Where there is this public folder?
root C:/home/localhost/public_html/public; - kylie commented on March 19th 20 at 09:17
@kylie, on the intranet root site "C:\Winginx\home\localhost\public_html" there's already two folders app public file and htaccess with redirect in public, which has the same index.php and next to another htaccess with CNC and redirect to static as I understand it - Ruthe.Von96 commented on March 19th 20 at 09:20
@hcodeorg, then root C:/Winginx/home/localhost/public_html/public; - kylie commented on March 19th 20 at 09:23
You won it:D Thank you!
If you don't mind, on the host of course another path (UNIX) to trim /public (since this is the directory of the script) and leave the root /public_html allow:?
location / {
 try_files $uri $uri/ @php;
}

 location @php {
 rewrite ^/(.*) /public/index.php?url=$1;
 }
- Ruthe.Von96 commented on March 19th 20 at 09:26
@hcodeorg, then you need to add the public and in try_files to a request for /file.css to give it /public/file.css
location / {
 try_files /public$uri /public$uri/ @php;
 }
- kylie commented on March 19th 20 at 09:29
@kylie, Perfect! Thanks again) - Ruthe.Von96 commented on March 19th 20 at 09:32

Find more questions by tags htaccessNginx