переписать правила apache2 to nginx - PullRequest
0 голосов
/ 23 января 2019

Я пытаюсь использовать свое веб-приложение (на основе Symfony 4) с nginx вместо apache2.

Моя рабочая конфигурация apache выглядит следующим образом:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

Конфигурация по умолчаниюФайл nginx vhost выглядит следующим образом:

server {
server_name myapp.test;
root /home/habeeb/myapp/public;

location / {
    # try to serve file directly, fallback to app.php
    try_files $uri /index.php$is_args$args;


}

location ~ ^/index\.php(/|$) {
    fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;


    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;

    internal;
}

# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
  return 404;
}



error_log /var/log/nginx/myapp_error.log;
access_log /var/log/nginx/myapp_access.log;

}

Как я могу настроить файл конфигурации nginex так, чтобы он действовал подобно описанному выше htaccess?Спасибо тебе

...