V
V
Vasily minodvesP2014-07-16 12:05:20
Nginx
Vasily minodvesP, 2014-07-16 12:05:20

Is there a file equivalent of .htaccess for nginx and lighttpd?

hello! I'm interested in this:
Apache has a .htaccess file, which is usually located in the root folder of the site. Is there a similar way (writing the appropriate settings in a separate file a la htaccess) for Nginx and LightTPD servers?
I tried to "google" and "yandexit" - I did not really find anything. :(

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
galynsky, 2014-07-16
@benoni

On Nginx, this is all done via nginx.conf . All rules are written there. If you have .htaccess, then you can convert Apache instructions to Nginx, for example, using this service . Everything is solved.

D
Dmitry Entelis, 2014-07-16
@DmitriyEntelis

We have development on apache and production / dev servers on nginx.
As a result, we assembled a mini script to automate the conversion:
In the nginx config, we included a separate file into which we write the updated code from the script.
We do not use specific instructions, so all code is conditionally

$htaccess = file('.htaccess');
foreach ($htaccess as $line)
{
  if (substr($line,0,11) == 'RewriteRule')
  {
    $line = str_replace('RewriteRule ^','rewrite ^/',$line);
    $line = str_replace('[QSA,L]','last;',$line);
    echo $line, "\n";
  }
}

Well, we do nginx reload after that
In general, it all looks like this for us:
nginx config for the domain
server {
  server_name  mysite.com;
  set $site_root '/www/mysite.com';
  ...
  include /etc/nginx/conf.d/mysite.com-rewrite.inc;
  ...
}

There is a self-written deployment system, when you need to do a deployment, it just starts conditionally
php _redirect_maker.php > /etc/nginx/conf.d/mysite.com-rewrite.inc
service nginx reload

P
Puma Thailand, 2014-07-16
@opium

there are no analogues
litespeed supports .htaccess from Apache but it is paid

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question