Today i had to redirect a url to a specific folder on a server running on nginx. Usually i’d have done that with a .htaccess  file on an apache server. Here, i had to find the nginx equivalent to the .htaccess file and fill it with the right configuration.

In my case i needed to redirect http://mydomain.com  to http://mydomain.com/folderOne/otherfolder .

On my server, the nginx configuration file nginx.conf  was located at: /etc/nginx/ .

You can check what’s inside with a cat nginx.conf  or directly edit it with nano (or vim) with nano nginx.conf .

Then i just added a location directive in the server context like so:

Once this got written and saved, i just had to restart the nginx server for the changes to be applied with service nginx reload.  Reload doesn’t seem to cause any downtime compared to restart. But i’m no expert.  I’ve seen that you can as well send an HUP signal after finding the PID number of the master process with ps aux | grep nginx .

More at the nginx doc.

Useful: .htacces to nginx converter.

EDIT (07/08/16):

We found a shorter solution by changing the structure of our project down to folderOne only and setting the root of the server directive to /usr/share/nginx/html/folderOne;  because we wanted as well do a rewrite of the url to display only mydomain.com  and not mydomain.com/folderOne/folderTwo (but still pointing at mydomain.com/folderOne/folderTwo ). Setup that so far doesn’t appear to be possible.

Try. Fail. Adapt. Repeat. Succeed.

  • Edit: just saw that the post was all messed up. Will fix it asap.

Past Work

Soloteste

Design & development
Visit live site

Pousada Corsário

Design & development
Details Visit live site

Sydney Colombani

Design & development
Visit live site

Brecha

Development
Visit live site

Julia Queima

Design & development
Visit live site

Costa Brasilis

Design & Developement
Details

A3Interiores

Wp Development
Visit live site

ValorCafé e-commerce

Design
Details Visit live site

Oficina de Arquitetos

Development
Visit live site

Cani.tv

Development
Visit live site

Zee Champanheria

App design
Details

Rioow

Design & development
Details

ASBEA/RJ

Design & development
Details Visit live site

ValorCafé

Design & development
Details Visit live site

Livraria da Travessa

Design & development
Details Visit live site

Furafila

App design
Details

NETbureau

Design & development
Details Visit live site

About

So, i'm a developer from France currently living in Rio de Janeiro. I do code for the front-end side of the web with things like javascript, html, css, preprocessors, tasks runners, version control, frameworks, tdd, CI, Wordpress and others.

I do speak english, portuguese and french, read tons of books, love to play on a wake, bmx and snowboard and would like to travel to the Karakoram range, Tierra del Fuego and Mongolia.

I do appreciate you stopping by and admit i did abuse of the auxiliary verb do in this about.