Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have one Question. How can I use my Htaccess File on nginx?

I have seen something like that: http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

But I don't know if this is working and where should I put the Codes in?

Can someone help it would be awesome!

Greetings Slaxxer

share|improve this question

1 Answer 1

NGINX doesn't have support for anything like .htaccess (Unless I'm mistaken) so you'll need to put the rules into an NGINX config file, probably within a virtual host.

A virtual host is the specific configuration for a domain, within the NGINX config it will look like

  server { # simple reverse-proxy
    listen       80;
    server_name  domain2.com www.domain2.com;
    access_log   logs/domain2.access.log  main;

    location / {
      proxy_pass      http://127.0.0.1:8080;
    }
  }

(Taken from the NGINX sample config)
So you would put your converted .htaccess rules within the location{} square brackets (Equivalent to Apache's ).
To give a full example, say I have some URL rewrites in my .htaccess file

#Enable URL Rewriting
RewriteEngine on

#Rewrite some pages
RewriteRule ^page/([0-9a-zA-Z_-]+).html$ /pagehander.php?page=$1 [QSA]

Running it through the converter I get

rewrite ^/page/([0-9a-zA-Z_-]+).html$ /pagehander.php?page=$1;

So I would put that in my NGINX server config like

  server { # simple reverse-proxy
    listen       80;
    server_name  domain2.com www.domain2.com;
    access_log   logs/domain2.access.log  main;

    location / {
rewrite ^/page/([0-9a-zA-Z_-]+).html$ /pagehander.php?page=$1;
      proxy_pass      http://127.0.0.1:8080;
    }
  }
share|improve this answer
    
How do you mean Virtual Host? Another guy told me also that but I don't understand it.. –  Slaxxer May 8 '11 at 17:25
    
@Slaxxer Edited the post to give a bit more info. –  sam May 8 '11 at 19:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.