Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I do the following in nginx?

I have a website hosted on, I want to have my domainname linked to that url. I also want that the domain name in the url sticks to instead of the url.

So -->

I currently have the following in nginx but the url doesn't sticks to

server {
access_log /srv/www/;
error_log /srv/www/;
root /srv/www/;

location / {
    rewrite ^/ break;


Is this possible in nginx?

share|improve this question
2 domains point to same server? If so, what does directory structure look like? – quanta Oct 4 '11 at 18:11
Just like most hosters do (cloaked domains), They don't need to be on the same server. But in my case they are. – Ward Oct 4 '11 at 18:16
What is document root of – quanta Oct 4 '11 at 18:30
well there is a way to give a redirect code such as 301 or 301 but that literally says "visit that url instead". You can use location and alias and such to say /thing maps to this folder but thats about all i know you may do – acidzombie24 Oct 20 '11 at 8:17

Simple answer: No.

Nginx cannot do rewrites across hostnames, it can only rewrite the URI. You can either do it another way or you'll have to use something other than Nginx.

share|improve this answer

Maybe you want to think about using nginx as a reverse proxy for Something like this might be interesting for you:

server {
               location /  {
share|improve this answer

Your Answer


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.