A
A
Alexander Muskatin2019-03-29 02:03:48
Nginx
Alexander Muskatin, 2019-03-29 02:03:48

Converting .htaccess to NGINX - how?

Hello everybody! There is a site root, there are two folders in it

app
and
public
next to it lies .htaccess with the code
RewriteEngine on
RewriteRule ^(.*)   public/$1   [L]

The app folder does not have Apache files . It is in the public
folder , its code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$   $1                 [L]
RewriteRule ^(.*)$   index.php?url=$1   [QSA,L]

there is an index.php file right there.
In the script code itself, there is a built-in CNC. Because of all this porridge provided for Apache, I can’t make a working config
The most working option
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$ {
    fastcgi_pass 127.0.0.1:9071;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    include fastcgi_params;
  }

}

but the CNC does not work and the error of one static file, although the path is correct.
Google was used, docks were read. I hope for your help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-03-29
@fegase

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$ {
    fastcgi_pass 127.0.0.1:9071;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

}

A
Andrey Gavrilov, 2019-03-30
@thexaver

www.anilcetin.com/convert-apache-htaccess-to-nginx
winginx.com/ru/htaccess

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question