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

How can I do the following in nginx?

I have a website hosted on example.com/id/44, I want to have my domainname test.com linked to that url. I also want that the domain name in the url sticks to test.com instead of the example.com url.

So test.com --> example.com/id/44

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

server {
server_name www.test.eu test.eu;
access_log /srv/www/www.test.eu/logs/access.log;
error_log /srv/www/www.test.eu/logs/error.log;
root /srv/www/www.test.eu/public_html/src/public;

location / {
    rewrite ^/ http://www.example.com/id/5 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 example.com? –  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

2 Answers 2

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 test.com. Something like this might be interesting for you:

server test.com {
               location /  {
                       proxy_pass http://www.example.com/id/5;
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.