Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the nginx equivalent of .htaccess

Tags:

nginx

server

I have shifted my web hosting which support nginx only. But i have no daam idea about it. Just wanted to know what is the .htaccess equivalent for nginx. What should be its file name, where should it be saved. Also if you can help me on redirecting all request on my website to https://www it will be an cherry on cake.

Edit: I have got the answer some where else but dont know what should be the name it should be saved with and where

like image 970
Punit Makwana Avatar asked Sep 11 '15 12:09

Punit Makwana


People also ask

Does nginx have htaccess?

Nginx does not use . htaccess files like Apache does. This means that configuration previously done in . htaccess files now has to be done in a different format, explained in the Nginx documentation.

Where is .htaccess file in nginx?

htaccess files from custom locations, the contents of this file can be found in the installdir/apache2/conf/vhosts/htaccess/APPNAME-htaccess. conf file. For example: The installdir/apache2/conf/vhosts/APPNAME-vhost.

Does nginx ignore htaccess?

Nginx doesn't support . htaccess (see here: "You can't do this. You shouldn't.


1 Answers

Since Nginx does not have an equivalent to the .htaccess file (i.e. no directory level configuration files), you need to update the main configuration and reload nginx for any changes to take effect.

The above Apache config essentially reads "if the path provided isn't an existing file or a directory, redirect to index.php, appending the path".

In Nginx, you will use the try_files directive to accomplish the same thing:

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

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

By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf , /etc/nginx or /usr/local/etc/nginx

like image 171
Peyman.H Avatar answered Oct 03 '22 02:10

Peyman.H