Welcome! Log In Create A New Profile

Advanced

apache2nginx migration

Posted by Habeeb 
apache2nginx migration
January 23, 2019 02:00PM
Hello people,
I'm trayning to migrate my php application from apache 2 server to use nginx, i have some issues configuring some rewrite rules.
My application is Symfony-based (php).

.htaccess configuration is as follows:

<pre><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></pre>

Mu current application nginx configuration as follows:

<pre>
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;

}
</pre>

Could you help me to update this configuration to get the same behaviour as .htaccess above ?

thank you very much !
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 162
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready